我有这样的模型:
class User < ActiveRecord::Base
validates_length_of :name, :in => (2..5)
end
Run Code Online (Sandbox Code Playgroud)
我想测试一下这个验证:
it "should not allow too short name" do
u = User.new(:name => "a")
u.valid?
u.should have(1).error_on(:name)
end
Run Code Online (Sandbox Code Playgroud)
但是它没有测试设置了哪种错误name.我想知道,如果是too_short,too_long,或者一些其它的验证失败.
我可以在errors数组中查找消息文本,如下所示:
u.errors[:name].should include(I18n.t("activerecord.errors.models.user.attributes.name.too_short"))
Run Code Online (Sandbox Code Playgroud)
但是当我activerecord.errors.messages.too_short在locale文件中设置而不是特定于模型的消息时,这将失败.
那么,是否可以检查出现了哪种错误?
我使用wget如下:
wget --page-requisites --convert-links -e robots=off \
--span-hosts --restrict-file-names=windows \
--directory-prefix=$ASSETS_DIR --no-directories http://myhost/home
Run Code Online (Sandbox Code Playgroud)
HTML页面引用样式表文件application.css,其中包括以下内容:
@import url(https://fonts.googleapis.com/css?family=Quicksand:700);
Run Code Online (Sandbox Code Playgroud)
wget正确创建一个css@family=Quicksand%3A700包含以下内容的文件:
@font-face {
font-family: 'Quicksand';
font-style: normal;
font-weight: 700;
src: local('Quicksand Bold'), local('Quicksand-Bold'), url(https://themes.googleusercontent.com/static/fonts/quicksand/v3/32nyIRHyCu6iqEka_hbKsonF5uFdDttMLvmWuJdhhgs.ttf) format('truetype');
}
Run Code Online (Sandbox Code Playgroud)
但是,wget不会下载此处引用的实际TTF文件.当我更改镜像页面上的CSS并@font-face直接粘贴规则时application.css,它会下载TTF文件.(但我不想那样做 - 我更喜欢继续使用@import谷歌字体).
有没有办法强制wget解析@imported样式表并下载其引用?
我有一个基于RestKit的应用程序与一个映射类.一切似乎都很好.但是,当我检索对象时,RestKit会发出警告:
W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...
Run Code Online (Sandbox Code Playgroud)
警告出现两次(可能是因为JSON响应中有两个对象).我该如何解决这个问题?
这是我的映射:
RKManagedObjectMapping* presentationMapping = [RKManagedObjectMapping mappingForClass:[Presentation class]];
presentationMapping.primaryKeyAttribute = @"presentationId";
[presentationMapping mapKeyPath:@"id" toAttribute:@"presentationId"];
[presentationMapping mapKeyPath:@"title" toAttribute:@"title"];
[presentationMapping mapKeyPath:@"description" toAttribute:@"descriptionText"];
[presentationMapping mapKeyPath:@"download_url" toAttribute:@"downloadUrlString"];
[presentationMapping mapKeyPath:@"download_file_size" toAttribute:@"downloadFileSize"];
[objectManager.mappingProvider setMapping:presentationMapping forKeyPath:@"presentation"];
Run Code Online (Sandbox Code Playgroud)
这是我检索对象的方法:
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/presentations" delegate:self];
Run Code Online (Sandbox Code Playgroud)
这是我的JSON结构(通过curl检索):
[
{
"presentation": {
"created_at":"2011-08-13T17:09:40+02:00",
"description":"Lorem ipsum",
"id":1,
"title":"Xxx",
"updated_at":"2011-08-13T17:09:40+02:00",
"download_url":"http://xxx.example.com/system/downloads/1/original/presentation1.zip?1313248180",
"download_file_size":171703
}
},
{
"presentation": {
"created_at":"2011-08-13T17:10:30+02:00",
"description":"Dolor sit amet",
"id":2,
"title":"Zzz",
"updated_at":"2011-08-15T00:22:10+02:00",
"download_url":"http://xxx.example.com/system/downloads/2/original/zzz.zip?1313360530",
"download_file_size":3182117
}
}
]
Run Code Online (Sandbox Code Playgroud)
服务器是我控制的Rails 3.0应用程序,如果需要可以修改响应格式. …
是否可以在Doctrine_RawSql查询中使用聚合值?这是我正在尝试做的事情:
$q = new Doctrine_RawSql();
$q->select('{q.*}, AVG(a.value) AS avg');
$q->from('-- complex from clause');
$q->addComponent('q', 'Question');
Run Code Online (Sandbox Code Playgroud)
但是,Doctrine创建的SQL仅保留表中的列question并省略聚合值avg.
activerecord ×1
css ×1
doctrine ×1
doctrine-1.2 ×1
objective-c ×1
php ×1
restkit ×1
rspec ×1
testing ×1
validation ×1
wget ×1