Browse Source

factory methods in rspec

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
b8aafe1ab6
  1. 6
      spec/models/domain_spec.rb
  2. 4
      spec/support/application.rb
  3. 4
      spec/support/factory_girl.rb
  4. 6
      spec/support/shared_context/data.rb

6
spec/models/domain_spec.rb

@ -34,14 +34,14 @@ describe Domain do
it "protects DOS on more Settings.max_domains_per_user+ domains" do it "protects DOS on more Settings.max_domains_per_user+ domains" do
max = Settings.max_domains_per_user.to_i max = Settings.max_domains_per_user.to_i
domain.stub_chain(:user, :domains, :count).and_return(max) domain.stub_chain('user.domains.count').and_return(max)
domain.max_domains_per_user domain.max_domains_per_user
domain.should have(1).errors domain.should have(1).errors
end end
it "is DOS-valid on less than Settings.max_domains_per_user domains" do it "is DOS-valid on less than Settings.max_domains_per_user domains" do
max = Settings.max_domains_per_user.to_i max = Settings.max_domains_per_user.to_i
domain.stub_chain(:user, :domains, :count).and_return(max-1) domain.stub_chain('user.domains.count').and_return(max - 1)
domain.max_domains_per_user domain.max_domains_per_user
domain.should be_valid domain.should be_valid
end end
@ -54,7 +54,7 @@ describe Domain do
domain.should be_valid domain.should be_valid
# stub a parent domain on another user account # stub a parent domain on another user account
Domain.stub_chain(:find_by_name, :user_id).and_return(domain.user_id+1) Domain.stub_chain('find_by_name.user_id').and_return(domain.user_id + 1)
domain.should have(1).errors_on(:name) domain.should have(1).errors_on(:name)
end end

4
spec/support/application.rb

@ -1,4 +1,4 @@
module AngelNest module Entrydns
module TestHelpers module TestHelpers
# def make_user # def make_user
@ -8,5 +8,5 @@ module AngelNest
end end
RSpec.configure do |config| RSpec.configure do |config|
config.include AngelNest::TestHelpers config.include Entrydns::TestHelpers
end end

4
spec/support/factory_girl.rb

@ -0,0 +1,4 @@
RSpec.configure do |config|
config.include Factory::Syntax::Methods
end

6
spec/support/shared_context/data.rb

@ -1,16 +1,16 @@
shared_context "data" do shared_context "data" do
let(:user){Factory(:user)} let(:user){create(:user)}
let(:domain){ let(:domain){
domain = Factory.build(:domain, :user => user) domain = build(:domain, :user => user)
domain.setup(FactoryGirl.generate(:email)) domain.setup(FactoryGirl.generate(:email))
domain.save! domain.save!
domain.soa_record.update_serial! domain.soa_record.update_serial!
domain domain
} }
let(:a_record){Factory(:a, :content => '127.0.0.1', :domain => domain)} let(:a_record){create(:a, :content => '127.0.0.1', :domain => domain)}
let(:soa_record){domain.soa_record} let(:soa_record){domain.soa_record}

Loading…
Cancel
Save