diff --git a/app/models/locomotive/ability.rb b/app/models/locomotive/ability.rb index eeb46f02..54c7bc19 100644 --- a/app/models/locomotive/ability.rb +++ b/app/models/locomotive/ability.rb @@ -32,7 +32,7 @@ module Locomotive can :touch, [Page, ThemeAsset] can :sort, Page - can :manage, [ContentInstance, Asset] + can :manage, [ContentInstance, ContentAsset] can :touch, Site do |site| site == @site @@ -50,7 +50,7 @@ module Locomotive can :manage, ThemeAsset - can :manage, Asset + can :manage, ContentAsset can :manage, Site do |site| site == @site @@ -82,4 +82,4 @@ module Locomotive end end end -end \ No newline at end of file +end diff --git a/app/models/locomotive/account.rb b/app/models/locomotive/account.rb index 0bd6a1df..9a47801c 100644 --- a/app/models/locomotive/account.rb +++ b/app/models/locomotive/account.rb @@ -27,7 +27,7 @@ module Locomotive end def reset_switch_site_token! - self.switch_site_token = ActiveSupport::SecureRandom.base64(8).gsub("/", "_").gsub(/=+$/, "") + self.switch_site_token = SecureRandom.base64(8).gsub("/", "_").gsub(/=+$/, "") self.save end @@ -37,7 +37,7 @@ module Locomotive end def self.find_using_switch_site_token!(token, age = 1.minute) - self.find_using_switch_site_token(token, age) || raise(Mongoid::Errors::DocumentNotFound.new(self, token)) + self.find_using_switch_site_token(token, age) || raise(::Mongoid::Errors::DocumentNotFound.new(self, token)) end def devise_mailer @@ -67,4 +67,4 @@ module Locomotive end end -end \ No newline at end of file +end diff --git a/spec/models/locomotive/account_spec.rb b/spec/models/locomotive/account_spec.rb index c8f429a8..d866bce3 100644 --- a/spec/models/locomotive/account_spec.rb +++ b/spec/models/locomotive/account_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Account do +describe Locomotive::Account do it 'should have a valid factory' do FactoryGirl.build(:account).should be_valid @@ -17,7 +17,7 @@ describe Account do end it "should have a default locale" do - account = Account.new + account = Locomotive::Account.new account.locale.should == 'en' end @@ -31,8 +31,8 @@ describe Account do it 'should own many sites' do account = FactoryGirl.create(:account) - site_1 = FactoryGirl.create(:site, :memberships => [Membership.new(:account => account)]) - site_2 = FactoryGirl.create(:site, :subdomain => 'foo', :memberships => [Membership.new(:account => account)]) + site_1 = FactoryGirl.create(:site, :memberships => [Locomotive::Membership.new(:account => account)]) + site_2 = FactoryGirl.create(:site, :memberships => [Locomotive::Membership.new(:account => account)]) account.reload.sites.to_a.should == [site_1, site_2] end @@ -40,14 +40,14 @@ describe Account do before(:each) do @account = FactoryGirl.build(:account) - @site_1 = FactoryGirl.build(:site, :subdomain => 'foo', :memberships => [FactoryGirl.build(:membership, :account => @account)]) - @site_2 = FactoryGirl.build(:site, :subdomain => 'bar', :memberships => [FactoryGirl.build(:membership, :account => @account)]) + @site_1 = FactoryGirl.build(:site,:memberships => [FactoryGirl.build(:membership, :account => @account)]) + @site_2 = FactoryGirl.build(:site,:memberships => [FactoryGirl.build(:membership, :account => @account)]) @account.stubs(:sites).returns([@site_1, @site_2]) - Site.any_instance.stubs(:save).returns(true) + Locomotive::Site.any_instance.stubs(:save).returns(true) end it 'should also delete memberships' do - Site.any_instance.stubs(:admin_memberships).returns(['junk', 'dirt']) + Locomotive::Site.any_instance.stubs(:admin_memberships).returns(['junk', 'dirt']) @site_1.memberships.first.expects(:destroy) @site_2.memberships.first.expects(:destroy) @account.destroy @@ -78,13 +78,13 @@ describe Account do context 'retrieving an account' do it 'does not find it with an empty token' do - Account.find_using_switch_site_token(nil).should be_nil + Locomotive::Account.find_using_switch_site_token(nil).should be_nil end it 'raises an exception if not found' do - lambda { - Account.find_using_switch_site_token!(nil) - }.should raise_error(Mongoid::Errors::DocumentNotFound) + expect { + Locomotive::Account.find_using_switch_site_token!(nil) + }.to raise_error Mongoid::Errors::DocumentNotFound end end diff --git a/spec/models/locomotive/asset_spec.rb b/spec/models/locomotive/content_asset_spec.rb similarity index 72% rename from spec/models/locomotive/asset_spec.rb rename to spec/models/locomotive/content_asset_spec.rb index 58b4afc6..fb884356 100644 --- a/spec/models/locomotive/asset_spec.rb +++ b/spec/models/locomotive/content_asset_spec.rb @@ -2,23 +2,23 @@ require 'spec_helper' -describe Asset do +describe Locomotive::ContentAsset do describe 'attaching a file' do before(:each) do - Asset.any_instance.stubs(:site_id).returns('test') + ContentAsset.any_instance.stubs(:site_id).returns('test') @asset = FactoryGirl.build(:asset) end it 'should process picture' do - @asset.source = FixturedAsset.open('5k.png') + @asset.source = FixturedContentAsset.open('5k.png') @asset.source.file.content_type.should_not be_nil @asset.image?.should be_true end it 'should get width and height from the image' do - @asset.source = FixturedAsset.open('5k.png') + @asset.source = FixturedContentAsset.open('5k.png') @asset.width.should == 32 @asset.height.should == 32 end @@ -28,7 +28,7 @@ describe Asset do describe 'vignette' do before(:each) do - @asset = FactoryGirl.build(:asset, :source => FixturedAsset.open('5k.png')) + @asset = FactoryGirl.build(:asset, :source => FixturedContentAsset.open('5k.png')) end it 'does not resize image smaller than 50x50' do @@ -43,4 +43,4 @@ describe Asset do end -end \ No newline at end of file +end diff --git a/spec/models/locomotive/content_instance_spec.rb b/spec/models/locomotive/content_instance_spec.rb index 9669ab61..3f35d9a4 100644 --- a/spec/models/locomotive/content_instance_spec.rb +++ b/spec/models/locomotive/content_instance_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ContentInstance do +describe Locomotive::ContentInstance do before(:each) do Site.any_instance.stubs(:create_default_pages!).returns(true) @@ -189,4 +189,4 @@ describe ContentInstance do def fake_bson_id(id) BSON::ObjectId(id.to_s.rjust(24, '0')) end -end \ No newline at end of file +end diff --git a/spec/models/locomotive/content_type_spec.rb b/spec/models/locomotive/content_type_spec.rb index 73f72679..8ce132e1 100644 --- a/spec/models/locomotive/content_type_spec.rb +++ b/spec/models/locomotive/content_type_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ContentType do +describe Locomotive::ContentType do before(:each) do Site.any_instance.stubs(:create_default_pages!).returns(true) diff --git a/spec/models/locomotive/editable_element_spec.rb b/spec/models/locomotive/editable_element_spec.rb index 79901bae..ec2f33c3 100644 --- a/spec/models/locomotive/editable_element_spec.rb +++ b/spec/models/locomotive/editable_element_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe EditableElement do +describe Locomotive::EditableElement do before(:each) do @site = FactoryGirl.create(:site) @@ -52,4 +52,4 @@ describe EditableElement do end end -end \ No newline at end of file +end diff --git a/spec/models/locomotive/membership_spec.rb b/spec/models/locomotive/membership_spec.rb index f2c5fffe..62a0d64b 100644 --- a/spec/models/locomotive/membership_spec.rb +++ b/spec/models/locomotive/membership_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Membership do +describe Locomotive::Membership do it 'should have a valid factory' do FactoryGirl.build(:membership, :account => FactoryGirl.build(:account)).should be_valid diff --git a/spec/models/locomotive/page_spec.rb b/spec/models/locomotive/page_spec.rb index 4e2fcaca..409c9522 100644 --- a/spec/models/locomotive/page_spec.rb +++ b/spec/models/locomotive/page_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Page do +describe Locomotive::Page do before(:each) do Site.any_instance.stubs(:create_default_pages!).returns(true) diff --git a/spec/models/locomotive/site_spec.rb b/spec/models/locomotive/site_spec.rb index fa434f73..21a069d2 100644 --- a/spec/models/locomotive/site_spec.rb +++ b/spec/models/locomotive/site_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Site do +describe Locomotive::Site do it 'should have a valid factory' do FactoryGirl.build(:site).should be_valid diff --git a/spec/models/locomotive/snippet_spec.rb b/spec/models/locomotive/snippet_spec.rb index 8f4a6d7e..a09d62da 100644 --- a/spec/models/locomotive/snippet_spec.rb +++ b/spec/models/locomotive/snippet_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Snippet do +describe Locomotive::Snippet do it 'should have a valid factory' do FactoryGirl.build(:snippet).should be_valid diff --git a/spec/models/locomotive/theme_asset_spec.rb b/spec/models/locomotive/theme_asset_spec.rb index 16abe137..e485c529 100644 --- a/spec/models/locomotive/theme_asset_spec.rb +++ b/spec/models/locomotive/theme_asset_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ThemeAsset do +describe Locomotive::ThemeAsset do describe 'attaching a file' do diff --git a/spec/support/factories.rb b/spec/support/factories.rb index 1d80a4df..eb87fa35 100644 --- a/spec/support/factories.rb +++ b/spec/support/factories.rb @@ -11,7 +11,7 @@ FactoryGirl.define do # subdomain 'test' after_build do |site_test| - site_test.memberships.build :account => Account.where(:name => "Admin").first || Factory("admin user"), :role => 'admin' + site_test.memberships.build :account => Locomotive::Account.where(:name => "Admin").first || Factory("admin user"), :role => 'admin' end factory "another site" do @@ -100,14 +100,14 @@ FactoryGirl.define do title 'Home page' slug 'index' published true - site { Site.where(:subdomain => "acme").first || Factory(:site) } + site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) } factory :sub_page do title 'Subpage' slug 'subpage' published true - site { Site.where(:subdomain => "acme").first || Factory(:site) } - parent { Page.where(:slug => "index").first || Factory(:page) } + site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) } + parent { Locomotive::Page.where(:slug => "index").first || Factory(:page) } end end @@ -117,25 +117,25 @@ FactoryGirl.define do name 'My website title' slug 'header' template %{Acme} - site { Site.where(:subdomain => "acme").first || Factory(:site) } + site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) } end ## Assets ## factory :asset, :class => Locomotive::ContentAsset do - site { Site.where(:subdomain => "acme").first || Factory(:site) } + site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) } end ## Theme assets ## factory :theme_asset, :class => Locomotive::ThemeAsset do - site { Site.where(:subdomain => "acme").first || Factory(:site) } + site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) } end ## Content types ## factory :content_type, :class => Locomotive::ContentType do name 'My project' - site { Site.where(:subdomain => "acme").first || Factory(:site) } + site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) } end factory :content_instance, :class => Locomotive::ContentInstance do diff --git a/spec/support/locomotive.rb b/spec/support/locomotive.rb index c054f2f3..374f90fd 100644 --- a/spec/support/locomotive.rb +++ b/spec/support/locomotive.rb @@ -29,11 +29,11 @@ def Locomotive.configure_for_test(force = false) Locomotive.define_subdomain_and_domains_options - Object.send(:remove_const, 'Site') if Object.const_defined?('Site') - load 'site.rb' + Object.send(:remove_const, 'Locomotive::Site') if Object.const_defined?('Locomotive::Site') + load 'locomotive/site.rb' FactoryGirl.factories.clear load File.join(Rails.root, 'spec', 'factories.rb') end end -end \ No newline at end of file +end