Specs now run for all models. The account model now passes GREEEEn.

This commit is contained in:
Mario Visic 2011-11-20 22:47:41 +11:00
parent a99ba18200
commit 75041ba21c
14 changed files with 45 additions and 45 deletions

View File

@ -32,7 +32,7 @@ module Locomotive
can :touch, [Page, ThemeAsset] can :touch, [Page, ThemeAsset]
can :sort, Page can :sort, Page
can :manage, [ContentInstance, Asset] can :manage, [ContentInstance, ContentAsset]
can :touch, Site do |site| can :touch, Site do |site|
site == @site site == @site
@ -50,7 +50,7 @@ module Locomotive
can :manage, ThemeAsset can :manage, ThemeAsset
can :manage, Asset can :manage, ContentAsset
can :manage, Site do |site| can :manage, Site do |site|
site == @site site == @site

View File

@ -27,7 +27,7 @@ module Locomotive
end end
def reset_switch_site_token! 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 self.save
end end
@ -37,7 +37,7 @@ module Locomotive
end end
def self.find_using_switch_site_token!(token, age = 1.minute) 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 end
def devise_mailer def devise_mailer

View File

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Account do describe Locomotive::Account do
it 'should have a valid factory' do it 'should have a valid factory' do
FactoryGirl.build(:account).should be_valid FactoryGirl.build(:account).should be_valid
@ -17,7 +17,7 @@ describe Account do
end end
it "should have a default locale" do it "should have a default locale" do
account = Account.new account = Locomotive::Account.new
account.locale.should == 'en' account.locale.should == 'en'
end end
@ -31,8 +31,8 @@ describe Account do
it 'should own many sites' do it 'should own many sites' do
account = FactoryGirl.create(:account) account = FactoryGirl.create(:account)
site_1 = FactoryGirl.create(:site, :memberships => [Membership.new(:account => account)]) site_1 = FactoryGirl.create(:site, :memberships => [Locomotive::Membership.new(:account => account)])
site_2 = FactoryGirl.create(:site, :subdomain => 'foo', :memberships => [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] account.reload.sites.to_a.should == [site_1, site_2]
end end
@ -40,14 +40,14 @@ describe Account do
before(:each) do before(:each) do
@account = FactoryGirl.build(:account) @account = FactoryGirl.build(:account)
@site_1 = FactoryGirl.build(:site, :subdomain => 'foo', :memberships => [FactoryGirl.build(:membership, :account => @account)]) @site_1 = FactoryGirl.build(:site,:memberships => [FactoryGirl.build(:membership, :account => @account)])
@site_2 = FactoryGirl.build(:site, :subdomain => 'bar', :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]) @account.stubs(:sites).returns([@site_1, @site_2])
Site.any_instance.stubs(:save).returns(true) Locomotive::Site.any_instance.stubs(:save).returns(true)
end end
it 'should also delete memberships' do 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_1.memberships.first.expects(:destroy)
@site_2.memberships.first.expects(:destroy) @site_2.memberships.first.expects(:destroy)
@account.destroy @account.destroy
@ -78,13 +78,13 @@ describe Account do
context 'retrieving an account' do context 'retrieving an account' do
it 'does not find it with an empty token' 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 end
it 'raises an exception if not found' do it 'raises an exception if not found' do
lambda { expect {
Account.find_using_switch_site_token!(nil) Locomotive::Account.find_using_switch_site_token!(nil)
}.should raise_error(Mongoid::Errors::DocumentNotFound) }.to raise_error Mongoid::Errors::DocumentNotFound
end end
end end

View File

@ -2,23 +2,23 @@
require 'spec_helper' require 'spec_helper'
describe Asset do describe Locomotive::ContentAsset do
describe 'attaching a file' do describe 'attaching a file' do
before(:each) do before(:each) do
Asset.any_instance.stubs(:site_id).returns('test') ContentAsset.any_instance.stubs(:site_id).returns('test')
@asset = FactoryGirl.build(:asset) @asset = FactoryGirl.build(:asset)
end end
it 'should process picture' do 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.source.file.content_type.should_not be_nil
@asset.image?.should be_true @asset.image?.should be_true
end end
it 'should get width and height from the image' do 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.width.should == 32
@asset.height.should == 32 @asset.height.should == 32
end end
@ -28,7 +28,7 @@ describe Asset do
describe 'vignette' do describe 'vignette' do
before(:each) do before(:each) do
@asset = FactoryGirl.build(:asset, :source => FixturedAsset.open('5k.png')) @asset = FactoryGirl.build(:asset, :source => FixturedContentAsset.open('5k.png'))
end end
it 'does not resize image smaller than 50x50' do it 'does not resize image smaller than 50x50' do

View File

@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ContentInstance do describe Locomotive::ContentInstance do
before(:each) do before(:each) do
Site.any_instance.stubs(:create_default_pages!).returns(true) Site.any_instance.stubs(:create_default_pages!).returns(true)

View File

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe ContentType do describe Locomotive::ContentType do
before(:each) do before(:each) do
Site.any_instance.stubs(:create_default_pages!).returns(true) Site.any_instance.stubs(:create_default_pages!).returns(true)

View File

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe EditableElement do describe Locomotive::EditableElement do
before(:each) do before(:each) do
@site = FactoryGirl.create(:site) @site = FactoryGirl.create(:site)

View File

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Membership do describe Locomotive::Membership do
it 'should have a valid factory' do it 'should have a valid factory' do
FactoryGirl.build(:membership, :account => FactoryGirl.build(:account)).should be_valid FactoryGirl.build(:membership, :account => FactoryGirl.build(:account)).should be_valid

View File

@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Page do describe Locomotive::Page do
before(:each) do before(:each) do
Site.any_instance.stubs(:create_default_pages!).returns(true) Site.any_instance.stubs(:create_default_pages!).returns(true)

View File

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Site do describe Locomotive::Site do
it 'should have a valid factory' do it 'should have a valid factory' do
FactoryGirl.build(:site).should be_valid FactoryGirl.build(:site).should be_valid

View File

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Snippet do describe Locomotive::Snippet do
it 'should have a valid factory' do it 'should have a valid factory' do
FactoryGirl.build(:snippet).should be_valid FactoryGirl.build(:snippet).should be_valid

View File

@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ThemeAsset do describe Locomotive::ThemeAsset do
describe 'attaching a file' do describe 'attaching a file' do

View File

@ -11,7 +11,7 @@ FactoryGirl.define do
# subdomain 'test' # subdomain 'test'
after_build do |site_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 end
factory "another site" do factory "another site" do
@ -100,14 +100,14 @@ FactoryGirl.define do
title 'Home page' title 'Home page'
slug 'index' slug 'index'
published true published true
site { Site.where(:subdomain => "acme").first || Factory(:site) } site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) }
factory :sub_page do factory :sub_page do
title 'Subpage' title 'Subpage'
slug 'subpage' slug 'subpage'
published true published true
site { Site.where(:subdomain => "acme").first || Factory(:site) } site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) }
parent { Page.where(:slug => "index").first || Factory(:page) } parent { Locomotive::Page.where(:slug => "index").first || Factory(:page) }
end end
end end
@ -117,25 +117,25 @@ FactoryGirl.define do
name 'My website title' name 'My website title'
slug 'header' slug 'header'
template %{<title>Acme</title>} template %{<title>Acme</title>}
site { Site.where(:subdomain => "acme").first || Factory(:site) } site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) }
end end
## Assets ## ## Assets ##
factory :asset, :class => Locomotive::ContentAsset do factory :asset, :class => Locomotive::ContentAsset do
site { Site.where(:subdomain => "acme").first || Factory(:site) } site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) }
end end
## Theme assets ## ## Theme assets ##
factory :theme_asset, :class => Locomotive::ThemeAsset do 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 end
## Content types ## ## Content types ##
factory :content_type, :class => Locomotive::ContentType do factory :content_type, :class => Locomotive::ContentType do
name 'My project' name 'My project'
site { Site.where(:subdomain => "acme").first || Factory(:site) } site { Locomotive::Site.where(:subdomain => "acme").first || Factory(:site) }
end end
factory :content_instance, :class => Locomotive::ContentInstance do factory :content_instance, :class => Locomotive::ContentInstance do

View File

@ -29,8 +29,8 @@ def Locomotive.configure_for_test(force = false)
Locomotive.define_subdomain_and_domains_options Locomotive.define_subdomain_and_domains_options
Object.send(:remove_const, 'Site') if Object.const_defined?('Site') Object.send(:remove_const, 'Locomotive::Site') if Object.const_defined?('Locomotive::Site')
load 'site.rb' load 'locomotive/site.rb'
FactoryGirl.factories.clear FactoryGirl.factories.clear
load File.join(Rails.root, 'spec', 'factories.rb') load File.join(Rails.root, 'spec', 'factories.rb')