Specs now run for all models. The account model now passes GREEEEn.
This commit is contained in:
parent
a99ba18200
commit
75041ba21c
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
end
|
@ -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
|
||||
end
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe ThemeAsset do
|
||||
describe Locomotive::ThemeAsset do
|
||||
|
||||
describe 'attaching a file' do
|
||||
|
||||
|
@ -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 %{<title>Acme</title>}
|
||||
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
|
||||
|
@ -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
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user