diff --git a/Gemfile.lock b/Gemfile.lock index 6e9250c0..6e877d9a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ GIT remote: git://github.com/floehopper/mocha.git - revision: 0ce0adc9f104a0ae2ddca400696c8694e85f1b93 + revision: f417066f7f1b7d66cf5c72f28380675bde0cc424 specs: mocha (0.9.12) - metaid (~> 1.0) + metaclass (~> 0.0.1) GEM remote: http://rubygems.org/ @@ -170,7 +170,7 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - metaid (1.0) + metaclass (0.0.1) mime-types (1.16) mimemagic (0.1.8) mimetype-fu (0.1.2) diff --git a/Rakefile b/Rakefile index a0405251..67c32df4 100644 --- a/Rakefile +++ b/Rakefile @@ -20,3 +20,52 @@ task :release => :gem do end task :default => [:spec, :cucumber] + +# only for running the tests suite in the order observed in *nix systems +task :spec_nix do + files = %w( + lib/core_ext_spec.rb + lib/locomotive/routing/site_dispatcher_spec.rb + lib/locomotive/bushido_spec.rb + lib/locomotive/render_spec.rb + lib/locomotive/httparty/patches_spec.rb + lib/locomotive/httparty/webservice_spec.rb + lib/locomotive/configuration_spec.rb + lib/locomotive/liquid/tags/consume_spec.rb + lib/locomotive/liquid/tags/with_scope_spec.rb + lib/locomotive/liquid/tags/nav_spec.rb + lib/locomotive/liquid/tags/editable/content_spec.rb + lib/locomotive/liquid/tags/editable/short_text_spec.rb + lib/locomotive/liquid/tags/seo_spec.rb + lib/locomotive/liquid/tags/paginate_spec.rb + lib/locomotive/liquid/drops/content_spec.rb + lib/locomotive/liquid/drops/contents_spec.rb + lib/locomotive/liquid/drops/page_spec.rb + lib/locomotive/liquid/drops/site_spec.rb + lib/locomotive/liquid/filters/resize_spec.rb + lib/locomotive/liquid/filters/html_spec.rb + lib/locomotive/liquid/filters/date_spec.rb + lib/locomotive/liquid/filters/text_spec.rb + lib/locomotive/liquid/filters/misc_spec.rb + lib/locomotive/heroku_spec.rb + lib/locomotive/import_spec.rb + lib/locomotive/export_spec.rb + models/content_instance_spec.rb + models/editable_element_spec.rb + models/account_spec.rb + models/content_type_spec.rb + models/snippet_spec.rb + models/ability_spec.rb + models/membership_spec.rb + models/page_spec.rb + models/asset_spec.rb + models/theme_asset_spec.rb + models/site_spec.rb + cells/admin/main_menu_cell_spec.rb + cells/admin/global_actions_spec.rb + cells/admin/settings_menu_cell_spec.rb + requests/seo_trailing_slash_spec.rb + ).collect { |f| File.join('spec', f) }.join(' ') + + sh "bundle exec rspec #{files}" +end \ No newline at end of file diff --git a/app/cells/admin/menu_cell.rb b/app/cells/admin/menu_cell.rb index 81cb9bc7..bc54789b 100644 --- a/app/cells/admin/menu_cell.rb +++ b/app/cells/admin/menu_cell.rb @@ -45,6 +45,7 @@ class Admin::MenuCell < Cell::Base block.call(MenuProxy.new(self)) end + # Note: this might cause "stack level too deep" if called twice for the same name alias_method_chain :build_list, name.to_sym end diff --git a/spec/cells/admin/global_actions_spec.rb b/spec/cells/admin/global_actions_spec.rb index b4c145ef..391f2d87 100644 --- a/spec/cells/admin/global_actions_spec.rb +++ b/spec/cells/admin/global_actions_spec.rb @@ -1,21 +1,5 @@ require 'spec_helper' -module Resetter - - @@original_global_actions_cell_klass = Admin::GlobalActionsCell - - def self.original_global_actions_cell_klass - @@original_global_actions_cell_klass - end - - def self.reset_global_actions_cell_klass - ::Admin.send(:remove_const, 'GlobalActionsCell') - ::Admin.const_set('GlobalActionsCell', self.original_global_actions_cell_klass.clone) - ::Admin::GlobalActionsCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' }) - end - -end - describe Admin::GlobalActionsCell do render_views @@ -25,7 +9,7 @@ describe Admin::GlobalActionsCell do describe 'show menu' do before(:each) do - Resetter.reset_global_actions_cell_klass + CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' }) end it 'has 3 links' do @@ -49,7 +33,7 @@ describe Admin::GlobalActionsCell do describe 'add a new menu item' do before(:each) do - Resetter.reset_global_actions_cell_klass + CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::GlobalActionsCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'My link', :url => 'http://www.locomotivecms.com') } end @@ -66,7 +50,7 @@ describe Admin::GlobalActionsCell do describe 'remove a new menu item' do before(:each) do - Resetter.reset_global_actions_cell_klass + CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::GlobalActionsCell.update_for(:testing_remove) { |m| m.remove(:see) } end @@ -83,7 +67,7 @@ describe Admin::GlobalActionsCell do describe 'modify an existing menu item' do before(:each) do - Resetter.reset_global_actions_cell_klass + CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::GlobalActionsCell.update_for(:testing_update) { |m| m.modify(:see, { :label => 'Modified !' }) } end @@ -98,4 +82,8 @@ describe Admin::GlobalActionsCell do end + after(:all) do + CellsResetter.clean! + end + end \ No newline at end of file diff --git a/spec/cells/admin/main_menu_cell_spec.rb b/spec/cells/admin/main_menu_cell_spec.rb index 0b6d7fac..ea2e1224 100644 --- a/spec/cells/admin/main_menu_cell_spec.rb +++ b/spec/cells/admin/main_menu_cell_spec.rb @@ -1,21 +1,5 @@ require 'spec_helper' -module Resetter - - @@original_main_menu_cell_klass = Admin::MainMenuCell - - def self.original_main_menu_cell_klass - @@original_main_menu_cell_klass - end - - def self.reset_main_menu_cell_klass - ::Admin.send(:remove_const, 'MainMenuCell') - ::Admin.const_set('MainMenuCell', self.original_main_menu_cell_klass.clone) - ::Admin::MainMenuCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' }) - end - -end - describe Admin::MainMenuCell do render_views @@ -25,7 +9,7 @@ describe Admin::MainMenuCell do describe 'show menu' do before(:each) do - Resetter.reset_main_menu_cell_klass + CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' }) end it 'has 2 items' do @@ -45,7 +29,7 @@ describe Admin::MainMenuCell do describe 'add a new menu item' do before(:each) do - Resetter.reset_main_menu_cell_klass + CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::MainMenuCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'Shop', :url => 'http://www.locomotivecms.com') } end @@ -62,7 +46,7 @@ describe Admin::MainMenuCell do describe 'remove a new menu item' do before(:each) do - Resetter.reset_main_menu_cell_klass + CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::MainMenuCell.update_for(:testing_remove) { |m| m.remove(:settings) } end @@ -79,7 +63,7 @@ describe Admin::MainMenuCell do describe 'modify an existing menu item' do before(:each) do - Resetter.reset_main_menu_cell_klass + CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::MainMenuCell.update_for(:testing_update) { |m| m.modify(:settings, { :label => 'Modified !' }) } end @@ -94,4 +78,8 @@ describe Admin::MainMenuCell do end + after(:all) do + CellsResetter.clean! + end + end \ No newline at end of file diff --git a/spec/cells/admin/settings_menu_cell_spec.rb b/spec/cells/admin/settings_menu_cell_spec.rb index 2f83ebfa..95db40b8 100644 --- a/spec/cells/admin/settings_menu_cell_spec.rb +++ b/spec/cells/admin/settings_menu_cell_spec.rb @@ -1,21 +1,5 @@ require 'spec_helper' -module Resetter - - @@original_settings_menu_cell_klass = Admin::SettingsMenuCell - - def self.original_settings_menu_cell_klass - @@original_settings_menu_cell_klass - end - - def self.reset_settings_menu_cell_klass - ::Admin.send(:remove_const, 'SettingsMenuCell') - ::Admin.const_set('SettingsMenuCell', self.original_settings_menu_cell_klass.clone) - ::Admin::SettingsMenuCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' }) - end - -end - describe Admin::SettingsMenuCell do render_views @@ -25,7 +9,7 @@ describe Admin::SettingsMenuCell do describe 'show menu' do before(:each) do - Resetter.reset_settings_menu_cell_klass + CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' }) end it 'has 3 items' do @@ -49,7 +33,7 @@ describe Admin::SettingsMenuCell do describe 'add a new menu item' do before(:each) do - Resetter.reset_settings_menu_cell_klass + CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::SettingsMenuCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'My link', :url => 'http://www.locomotivecms.com') } end @@ -66,7 +50,7 @@ describe Admin::SettingsMenuCell do describe 'remove a new menu item' do before(:each) do - Resetter.reset_settings_menu_cell_klass + CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::SettingsMenuCell.update_for(:testing_remove) { |m| m.remove(:theme_assets) } end @@ -83,7 +67,7 @@ describe Admin::SettingsMenuCell do describe 'modify an existing menu item' do before(:each) do - Resetter.reset_settings_menu_cell_klass + CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' }) Admin::SettingsMenuCell.update_for(:testing_update) { |m| m.modify(:theme_assets, { :label => 'Modified !' }) } end @@ -98,4 +82,8 @@ describe Admin::SettingsMenuCell do end + after(:all) do + CellsResetter.clean! + end + end \ No newline at end of file diff --git a/spec/factories.rb b/spec/factories.rb index 8633cf9e..cffcbca1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -23,13 +23,17 @@ Factory.define "existing site", :parent => "site" do |s| s.subdomain "models" s.after_build do |site_with_models| site_with_models.content_types.build( - :slug => 'projects', - :name => 'Existing name', + :slug => 'projects', + :name => 'Existing name', :description => 'Existing description', :order_by => 'created_at') end end +Factory.define "valid site", :parent => "site" do |s| + # s.after_build { |valid_site| valid_site.stubs(:valid?).returns(true) } +end + # Accounts ## Factory.define :account do |a| diff --git a/spec/lib/locomotive/bushido_spec.rb b/spec/lib/locomotive/bushido_spec.rb index 9c78f75f..3614e745 100644 --- a/spec/lib/locomotive/bushido_spec.rb +++ b/spec/lib/locomotive/bushido_spec.rb @@ -83,7 +83,7 @@ describe 'Bushido support' do before(:each) do configure_locomotive_with_bushido - (@site = Factory.build(:site)).stubs(:valid?).returns(true) + @site = Factory.build('valid site') end it 'calls add_bushido_domains after saving a site' do @@ -183,7 +183,6 @@ describe 'Bushido support' do end after(:all) do - ENV['APP_TLD'] = nil Locomotive.configure_for_test(true) end diff --git a/spec/lib/locomotive/heroku_spec.rb b/spec/lib/locomotive/heroku_spec.rb index 4ec886be..8e386f8d 100644 --- a/spec/lib/locomotive/heroku_spec.rb +++ b/spec/lib/locomotive/heroku_spec.rb @@ -2,10 +2,6 @@ require 'spec_helper' describe 'Heroku support' do - before(:all) do - Site.destroy_all - end - before(:each) do ::Heroku::Client.any_instance.stubs(:post).returns(true) ::Heroku::Client.any_instance.stubs(:delete).returns(true) @@ -99,7 +95,9 @@ describe 'Heroku support' do before(:each) do configure_locomotive_with_heroku - (@site = Factory.build(:site)).stubs(:valid?).returns(true) + # (@site = Factory.stub(:site)).stubs(:valid?).returns(true) + @site = Factory.build('valid site') + # (@site = Site.new(:name => 'foobar', :subdomain => 'acme')).stubs(:valid?).returns(true) end it 'calls add_heroku_domains after saving a site' do @@ -178,7 +176,6 @@ describe 'Heroku support' do end after(:all) do - ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil Locomotive.configure_for_test(true) end diff --git a/spec/lib/locomotive/import_spec.rb b/spec/lib/locomotive/import_spec.rb index 325409af..93e7eead 100644 --- a/spec/lib/locomotive/import_spec.rb +++ b/spec/lib/locomotive/import_spec.rb @@ -2,6 +2,11 @@ require 'spec_helper' describe Locomotive::Import::Job do + # before(:all) do + # # Site.destroy_all + # # Locomotive.configure_for_test(true) + # end + context 'when successful' do before(:all) do @@ -24,7 +29,7 @@ describe Locomotive::Import::Job do content_type = @site.content_types.where(:slug => 'projects').first content_type.content_custom_fields.size.should == 9 end - + it 'correctly imports content type names' do content_type = @site.content_types.where(:slug => 'projects').first content_type.name.should == 'My projects' @@ -73,7 +78,7 @@ describe Locomotive::Import::Job do page = @site.pages.where(:title => 'Contact').first page.find_editable_element('content', 'office').source_filename.should == 'office.jpg' end - + it 'sets the empty editable file for a page from the site config file' do page = @site.pages.where(:title => 'Contact').first page.find_editable_element('content', 'office2').source_filename.should be_nil @@ -100,7 +105,7 @@ describe Locomotive::Import::Job do end end - + context 'with an existing site' do before(:all) do @site = Factory("existing site") @@ -110,25 +115,24 @@ describe Locomotive::Import::Job do job.success nil end - + context 'updates to content_type attributes' do before(:all) do @projects = content_type = @site.content_types.where(:slug => 'projects').first end - + it 'includes new name' do @projects.name.should == 'My projects' end - + it 'includes new description' do @projects.description.should == 'My portfolio' end - + it 'includes new order by' do @projects.order_by.should == '_position_in_list' end end end - end diff --git a/spec/lib/locomotive/routing/site_dispatcher_spec.rb b/spec/lib/locomotive/routing/site_dispatcher_spec.rb index fcf26f97..ed30e267 100644 --- a/spec/lib/locomotive/routing/site_dispatcher_spec.rb +++ b/spec/lib/locomotive/routing/site_dispatcher_spec.rb @@ -70,7 +70,7 @@ describe Locomotive::Routing::SiteDispatcher do before :each do @controller.expects(:current_site).returns(true) end - + it 'returns true' do @controller.send(:require_site).should be_true end @@ -87,7 +87,7 @@ describe Locomotive::Routing::SiteDispatcher do @controller.stubs(:admin_installation_url).returns('/admin/install/url/') @controller.stubs(:redirect_to).with('/admin/install/url/') end - + it 'returns false' do @controller.send(:require_site).should be_false end @@ -98,7 +98,7 @@ describe Locomotive::Routing::SiteDispatcher do end end - + context 'when there are no sites' do before :each do @@ -110,7 +110,7 @@ describe Locomotive::Routing::SiteDispatcher do @controller.stubs(:admin_installation_url).returns('/admin/install/url/') @controller.stubs(:redirect_to).with('/admin/install/url/') end - + it 'returns false' do @controller.send(:require_site).should be_false end @@ -131,7 +131,7 @@ describe Locomotive::Routing::SiteDispatcher do @controller.instance_variable_set('@_response', ActionDispatch::Response.new) @controller.expects(:current_site).returns(false) end - + it 'returns false' do @controller.send(:require_site).should be_false end @@ -244,4 +244,8 @@ describe Locomotive::Routing::SiteDispatcher do end + # after(:all) do + # Locomotive.configure_for_test(true) + # end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 677d8c5e..08393244 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,26 @@ +# figure out where we are being loaded from +if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any? + begin + raise "foo" + rescue => e + puts <<-MSG + =================================================== + It looks like spec_helper.rb has been loaded + multiple times. Normalize the require to: + + require "spec/spec_helper" + + Things like File.join and File.expand_path will + cause it to be loaded multiple times. + + Loaded this time from: + + #{e.backtrace.join("\n ")} + =================================================== + MSG + end +end + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path('../../config/environment', __FILE__) @@ -49,4 +72,10 @@ RSpec.configure do |config| DatabaseCleaner.clean end end + + config.before(:all) do + if self.described_class == Locomotive::Import::Job + DatabaseCleaner.clean + end + end end diff --git a/spec/support/cells.rb b/spec/support/cells.rb index cc79ecdf..75fe18e3 100644 --- a/spec/support/cells.rb +++ b/spec/support/cells.rb @@ -1,3 +1,27 @@ require 'rspec-cells' require 'cell/test_case' -require 'rspec/rails/example/cell_example_group' \ No newline at end of file +require 'rspec/rails/example/cell_example_group' + +module CellsResetter + + def self.method_missing(meth, *args) + if meth =~ /^new_(.*)_klass/ + name = $1 + + klass_name = name.camelize + + ::Admin.send(:remove_const, klass_name) + load "#{name}.rb" + + "::Admin::#{klass_name}".constantize.any_instance.stubs(:sections).returns(args.first) + end + end + + def self.clean! + [:menu_cell, :main_menu_cell, :global_actions_cell, :settings_menu_cell].each do |name| + ::Admin.send(:remove_const, "#{name.to_s.camelize}") + load "#{name}.rb" + end + end + +end \ No newline at end of file diff --git a/spec/support/locomotive.rb b/spec/support/locomotive.rb index b09b06a2..c054f2f3 100644 --- a/spec/support/locomotive.rb +++ b/spec/support/locomotive.rb @@ -25,6 +25,8 @@ def Locomotive.configure_for_test(force = false) config.enable_logs = true if force + ENV['APP_TLD'] = ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil + Locomotive.define_subdomain_and_domains_options Object.send(:remove_const, 'Site') if Object.const_defined?('Site')