Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created April 11, 2012 12:55
Show Gist options
  • Save dchelimsky/2359140 to your computer and use it in GitHub Desktop.
Save dchelimsky/2359140 to your computer and use it in GitHub Desktop.
class Article < ActiveRecord::Base
validates_presence_of :title
has_many :comments
end
class Contract < ActiveRecord::Base
validates_presence_of :name
has_many :monthly_expenses
calculates_default_monthly_charge
end
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
describe Article do
it { should validate_presence_of(:title) }
end
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