Created
April 11, 2012 12:55
-
-
Save dchelimsky/2359140 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ActiveRecord::Base | |
validates_presence_of :title | |
has_many :comments | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contract < ActiveRecord::Base | |
validates_presence_of :name | |
has_many :monthly_expenses | |
calculates_default_monthly_charge | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RentalContract < ActiveRecord::Base | |
has_many :monthly_charges | |
has_one :rentable, :polymorphic => true | |
validates_presence_of :rentable | |
def default_monthly_charge | |
price / months_applied | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Article do | |
it { should validate_presence_of(:title) } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Article do | |
describe "#with_comments_by" do | |
it "finds articles with comments by the submitted comment_author" do | |
article = Factory(:article) | |
article.comments << Factory.build(:comment, :author => "jdoe") | |
Article.with_comments_by("jdoe").should eq([article]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment