有人能告诉我,如果我只是以错误的方式进行设置吗?
我有以下具有has_many.through关联的模型:
class Listing < ActiveRecord::Base
attr_accessible ...
has_many :listing_features
has_many :features, :through => :listing_features
validates_presence_of ...
...
end
class Feature < ActiveRecord::Base
attr_accessible ...
validates_presence_of ...
validates_uniqueness_of ...
has_many :listing_features
has_many :listings, :through => :listing_features
end
class ListingFeature < ActiveRecord::Base
attr_accessible :feature_id, :listing_id
belongs_to :feature
belongs_to :listing
end
Run Code Online (Sandbox Code Playgroud)
我正在使用Rails 3.1.rc4,FactoryGirl 2.0.2,factory_girl_rails 1.1.0和rspec.这是我对:listing工厂的基本rspec rspec健全性检查:
it "creates a valid listing from factory" do
Factory(:listing).should be_valid
end
Run Code Online (Sandbox Code Playgroud)
这是工厂(:上市)
FactoryGirl.define do
factory :listing do
headline 'headline'
home_desc 'this is the home …Run Code Online (Sandbox Code Playgroud) 有没有人有任何具体的理由使用一个autotesting跑步者而不是另一个?我已经使用了Autofeature + autotest,我真的很喜欢它设置的内置过程,它首先运行我的rspec单元测试,然后是黄瓜测试,只有最后一次失败测试 - 它适合标准编写黄瓜测试的工作流程,设置步骤直到它们失败,然后进入单元测试以获得详细功能.
我在标准的rspec配置中使用了Guard,它也运行良好,但我没有在黄瓜测试中折叠 - 没有时间进一步实验.
只是想知道是否有人有任何具体的理由使用一个在另一个,或一种方式减轻另一方的弱点.
谢谢你的意见,Tony
做第一个Project Euler问题:将3和5的倍数相加到1到1000之间,我想出了这个(非常简单)
sum = 0
1.upto(999) { |i| sum += i if 0 == i%3 || 0 == i%5 }
sum
Run Code Online (Sandbox Code Playgroud)
但我认为这会有效,但它没有,有人能告诉我我做错了什么,或者为什么它不起作用?
1.upto(999).inject(0) { |sum, i| sum + i if 0 == i%3 || 0 == i%5 }
Run Code Online (Sandbox Code Playgroud)
谢谢!
使用minitest发现本教程,并想知道rspec中是否存在等效的匹配器:
describe "default attributes" do
it "must include httparty methods" do
Dish::Player.must_include HTTParty
end
it "must have the base url set to the Dribble API endpoint" do
Dish::Player.base_uri.must_equal 'http://api.dribbble.com'
end
end
Run Code Online (Sandbox Code Playgroud) 如何显示 has_many_through 关联列表,其中关联作为列标题,而 through: 值作为表行中的条目?
我有 3 个模型:
class Jobs
attr_accesor :title
has_many :scores
has_many :factors, through: :scores
end
class Scores
attr_accesor :score
belongs_to :job
belongs_to :factor
end
class Factor
attr_accesor :name
has_many :scores
has_many :jobs, through: :scores
end
Run Code Online (Sandbox Code Playgroud)
我希望能够在 Jobs 索引中显示每个 Job 的一行,每个 Factor 的标题作为列标题,以及每个 Job 的分数作为单元格中的值。
我希望必须在app/admin/jobs.rb文件中做这样的事情:
index do |jobs|
column :title
jobs.scores.each do |score|
column(score.factor.name) { |score| score.score }
end
end
Run Code Online (Sandbox Code Playgroud)
并得到这样的输出:
Job | Education | Experience | Leadership | ... |
- - - …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails has-many-through ruby-on-rails-3 activeadmin