spec/models/locomotive/site_spec.rb in locomotive_cms-2.0.3 vs spec/models/locomotive/site_spec.rb in locomotive_cms-2.1.0

- old
+ new

@@ -9,37 +9,37 @@ end ## Validations ## it 'should validate presence of name' do - site = FactoryGirl.build(:site, :name => nil) + site = FactoryGirl.build(:site, name: nil) site.should_not be_valid site.errors[:name].should == ["can't be blank"] end it 'should validate presence of subdomain' do - site = FactoryGirl.build(:site, :subdomain => nil) + site = FactoryGirl.build(:site, subdomain: nil) site.should_not be_valid site.errors[:subdomain].should == ["can't be blank"] end %w{test test42 foo_bar}.each do |subdomain| it "should accept subdomain like '#{subdomain}'" do - FactoryGirl.build(:site, :subdomain => subdomain).should be_valid + FactoryGirl.build(:site, subdomain: subdomain).should be_valid end end ['-', '_test', 'test_', 't est', '42', '42test'].each do |subdomain| it "should not accept subdomain like '#{subdomain}'" do - (site = FactoryGirl.build(:site, :subdomain => subdomain)).should_not be_valid + (site = FactoryGirl.build(:site, subdomain: subdomain)).should_not be_valid site.errors[:subdomain].should == ['is invalid'] end end it "should not use reserved keywords as subdomain" do %w{www admin email blog webmail mail support help site sites}.each do |subdomain| - (site = FactoryGirl.build(:site, :subdomain => subdomain)).should_not be_valid + (site = FactoryGirl.build(:site, subdomain: subdomain)).should_not be_valid site.errors[:subdomain].should == ['is reserved'] end end it 'should validate uniqueness of subdomain' do @@ -47,30 +47,30 @@ (site = FactoryGirl.build(:site)).should_not be_valid site.errors[:subdomain].should == ["is already taken"] end it 'should validate uniqueness of domains' do - FactoryGirl.create(:site, :domains => %w{www.acme.net www.acme.com}) + FactoryGirl.create(:site, domains: %w{www.acme.net www.acme.com}) - (site = FactoryGirl.build(:site, :domains => %w{www.acme.com})).should_not be_valid + (site = FactoryGirl.build(:site, domains: %w{www.acme.com})).should_not be_valid site.errors[:domains].should == ["www.acme.com is already taken"] - (site = FactoryGirl.build(:site, :subdomain => 'foo', :domains => %w{acme.example.com})).should_not be_valid + (site = FactoryGirl.build(:site, subdomain: 'foo', domains: %w{acme.example.com})).should_not be_valid site.errors[:domains].should == ["acme.example.com is already taken"] end it 'should validate format of domains' do - site = FactoryGirl.build(:site, :domains => ['barformat.superlongextension', '-foo.net']) + site = FactoryGirl.build(:site, domains: ['barformat.a', '-foo.net', 'goodformat.superlong']) site.should_not be_valid - site.errors[:domains].should == ['barformat.superlongextension is invalid', '-foo.net is invalid'] + site.errors[:domains].should == ['barformat.a is invalid', '-foo.net is invalid'] end ## Named scopes ## it 'should retrieve sites by domain' do - site_1 = FactoryGirl.create(:site, :domains => %w{www.acme.net}) - site_2 = FactoryGirl.create(:site, :subdomain => 'test', :domains => %w{www.example.com}) + site_1 = FactoryGirl.create(:site, domains: %w{www.acme.net}) + site_2 = FactoryGirl.create(:site, subdomain: 'test', domains: %w{www.example.com}) sites = Locomotive::Site.match_domain('www.acme.net') sites.size.should == 1 sites.first.should == site_1 @@ -88,21 +88,21 @@ ## Associations ## it 'should have many accounts' do site = FactoryGirl.build(:site) - account_1, account_2 = FactoryGirl.create(:account), FactoryGirl.create(:account, :name => 'homer', :email => 'homer@simpson.net') - site.memberships.build(:account => account_1, :admin => true) - site.memberships.build(:account => account_2) + account_1, account_2 = FactoryGirl.create(:account), FactoryGirl.create(:account, name: 'homer', email: 'homer@simpson.net') + site.memberships.build(account: account_1, admin: true) + site.memberships.build(account: account_2) site.memberships.size.should == 2 site.accounts.should == [account_1, account_2] end ## Methods ## it 'should return domains without subdomain' do - site = FactoryGirl.create(:site, :domains => %w{www.acme.net www.acme.com}) + site = FactoryGirl.create(:site, domains: %w{www.acme.net www.acme.com}) site.domains.should == %w{www.acme.net www.acme.com acme.example.com} site.domains_without_subdomain.should == %w{www.acme.net www.acme.com} end describe 'once created' do @@ -115,11 +115,11 @@ @site.pages.size.should == 2 @site.pages.map(&:fullpath).sort.should == %w{404 index} end it 'translates the index/404 pages if a new locale is added' do - @site.update_attributes :locales => %w(en fr) + @site.update_attributes locales: %w(en fr) @site.errors.should be_empty ::Mongoid::Fields::I18n.with_locale('fr') do @site.pages.root.first.tap do |page| @@ -133,11 +133,11 @@ end end end it 'translates the index/404 pages if the default locale changes' do - @site.update_attributes :locales => %w(fr en) + @site.update_attributes locales: %w(fr en) @site.errors.should be_empty ::Mongoid::Fields::I18n.with_locale('fr') do @site.pages.root.first.tap do |page| @@ -151,10 +151,10 @@ end end end it 'does not allow to remove the default locale' do - @site.update_attributes :locales => %w(fr) + @site.update_attributes locales: %w(fr) @site.errors[:locales].should == ['The previous default locale can not be removed right away.'] end end