From cbeffaced1f6daf538cea28e4c41fa3cd7a3669f Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sun, 24 Feb 2013 17:36:19 +1100 Subject: [PATCH] Configure Travis, remove spork, add simplecov, add turbo sprokets. Add travis config (cherry picked from commit e3fdb122895bcd63477b2977252b73f49154a659) Only build on Ruby 1.9.3 (cherry picked from commit 719ef386bf522130352041bd1b0b543902c01dee) Exclude pry from CI build (cherry picked from commit d60935c800aeb42c365ec20525ced88d7113b064) Conflicts: Gemfile Attempt 2 (cherry picked from commit 2b19253895e2995c0a63d3c98464ef3b7c6a570c) Conflicts: Gemfile.lock Configure travis for postgres (cherry picked from commit 3a441cd7d98d14e1523e9589eac258c464dcd604) Fix migrations that fail because of coupling to changed/removed models (cherry picked from commit b030793f153b402670fafd307cb8d303c3193cea) Set up xvfb for Travis (cherry picked from commit cdc3ab09a18376b9b66b86ea000873cc14998d61) Add a failing test to test travis (cherry picked from commit 72aa8fe5e5f23d4a9551a3710920b23d60ab6cbb) Revert "Add a failing test to test travis" This reverts commit 72aa8fe5e5f23d4a9551a3710920b23d60ab6cbb. (cherry picked from commit bd5533e2b14d14ac53199faf2725ce4696efff16) Add simplecov (cherry picked from commit 5089d3bb22fc708ce556a17ef00c2821f49c8969) Conflicts: Gemfile.lock Add turbo sprockets for faster asset precompile (cherry picked from commit 3e6c56a638872dcab05b71aecef44561acf09a9d) Remove spork (cherry picked from commit ed7bded642a7439ee7849ed49bfa2a5caed2b68a) Conflicts: spec/spec_helper.rb Remove more spork-specific things, remove unused cuc config from zeus (cherry picked from commit fa11ff8982a231b063505254619133db6bf839e0) Ensure order decorator is required, fix test fragility (cherry picked from commit 1e94f88c5e5a7e2251ea098ef484b7358c06be30) --- .gitignore | 1 + .travis.yml | 14 +++ Gemfile | 10 +- Gemfile.lock | 12 +- README.markdown | 12 +- config/database.travis.yml | 4 + .../20120327000582_polymorphic_payments.rb | 1 + ..._move_distributor_from_order_to_product.rb | 3 + ...r_and_supplier_address_to_spree_address.rb | 5 + ...utors_products_to_product_distributions.rb | 5 +- script/rails | 6 + .../order_cycle_form_applicator_spec.rb | 2 +- spec/spec_helper.rb | 110 +++++++++--------- zeus.json | 1 - 14 files changed, 112 insertions(+), 74 deletions(-) create mode 100644 .travis.yml create mode 100644 config/database.travis.yml diff --git a/.gitignore b/.gitignore index 4996ff5ddf..6cb7536f07 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ public/spree config/abr.yml config/heroku_env.rb NERD_tree* +coverage diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..bb6927df9c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: ruby +bundler_args: --without development +rvm: + - "1.9.3" +services: postgresql +before_install: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" +before_script: + - cp config/database.travis.yml config/database.yml + - psql -c 'create database open_food_web_test;' -U postgres +script: + - RAILS_ENV=test bundle exec rake db:migrate --trace + - export DISPLAY=:99.0 && bundle exec rake spec diff --git a/Gemfile b/Gemfile index 192b978ad3..6ecf6fd807 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,8 @@ group :assets do gem 'therubyracer' gem 'uglifier', '>= 1.0.3' + + gem 'turbo-sprockets-rails3' end gem 'jquery-rails' @@ -52,8 +54,7 @@ group :test, :development do gem 'faker' gem 'capybara' gem 'database_cleaner', '0.7.1', :require => false - gem 'spork', '~> 1.0rc' - gem 'pry-debugger' + gem 'simplecov', :require => false gem 'awesome_print' gem 'letter_opener' gem 'timecop' @@ -64,3 +65,8 @@ group :chili do gem 'eaterprises_feature', path: 'lib/chili/eaterprises_feature' gem 'local_organics_feature', path: 'lib/chili/local_organics_feature' end + +group :development do + gem 'pry-debugger' + gem 'debugger-linecache' +end diff --git a/Gemfile.lock b/Gemfile.lock index e51e95d90f..a158e74c85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -371,8 +371,11 @@ GEM websocket (~> 1.0.4) shoulda-matchers (1.1.0) activesupport (>= 3.0.0) + simplecov (0.7.1) + multi_json (~> 1.0) + simplecov-html (~> 0.7.1) + simplecov-html (0.7.1) slop (3.3.3) - spork (1.0.0rc3) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -389,6 +392,9 @@ GEM polyglot polyglot (>= 0.3.1) truncate_html (0.5.5) + turbo-sprockets-rails3 (0.3.6) + railties (> 3.2.8, < 4.0.0) + sprockets (>= 2.0.0) turn (0.8.3) ansi tzinfo (0.3.37) @@ -420,6 +426,7 @@ DEPENDENCIES comfortable_mexican_sofa database_cleaner (= 0.7.1) db2fog + debugger-linecache deface! eaterprises_feature! enterprises_distributor_info_rich_text_feature! @@ -438,7 +445,7 @@ DEPENDENCIES sass-rails (~> 3.2.3) shoulda-matchers simple_form! - spork (~> 1.0rc) + simplecov spree! spree_i18n! spree_last_address! @@ -446,6 +453,7 @@ DEPENDENCIES therubyracer timecop truncate_html + turbo-sprockets-rails3 turn (~> 0.8.3) uglifier (>= 1.0.3) unicorn diff --git a/README.markdown b/README.markdown index 834f763654..27c303df51 100644 --- a/README.markdown +++ b/README.markdown @@ -59,15 +59,9 @@ Then the tests can be run with: bundle exec rspec spec The site is configured to use -[Spork](https://github.com/sporkrb/spork) to reduce the pre-test -startup time while Rails loads. To use it, first start up a spork -instance: - - bundle exec spork - -When that's ready, you can run RSpec with the --drb flag: - - bundle exec rspec --drb spec +[Zeus](https://github.com/burke/zeus) to reduce the pre-test +startup time while Rails loads. See the Zeus github page for +usage instructions. ## Deployment diff --git a/config/database.travis.yml b/config/database.travis.yml new file mode 100644 index 0000000000..712a914658 --- /dev/null +++ b/config/database.travis.yml @@ -0,0 +1,4 @@ +test: + adapter: postgresql + database: open_food_web_test + username: postgres diff --git a/db/migrate/20120327000582_polymorphic_payments.rb b/db/migrate/20120327000582_polymorphic_payments.rb index 418c3b30ce..33787c3d26 100644 --- a/db/migrate/20120327000582_polymorphic_payments.rb +++ b/db/migrate/20120327000582_polymorphic_payments.rb @@ -1,5 +1,6 @@ # Legacy table support class Checkout < ActiveRecord::Base; end; +class Spree::Creditcard < ActiveRecord::Base; end; class PolymorphicPayments < ActiveRecord::Migration def up diff --git a/db/migrate/20120618061537_move_distributor_from_order_to_product.rb b/db/migrate/20120618061537_move_distributor_from_order_to_product.rb index ede96641f1..c5f0b18a59 100644 --- a/db/migrate/20120618061537_move_distributor_from_order_to_product.rb +++ b/db/migrate/20120618061537_move_distributor_from_order_to_product.rb @@ -1,4 +1,7 @@ class MoveDistributorFromOrderToProduct < ActiveRecord::Migration + class Distributor < ActiveRecord::Base; end + class Spree::Product < ActiveRecord::Base; end + def up remove_column :spree_orders, :distributor_id diff --git a/db/migrate/20120626013846_extract_distributor_and_supplier_address_to_spree_address.rb b/db/migrate/20120626013846_extract_distributor_and_supplier_address_to_spree_address.rb index fdba0a03ef..89480427ea 100644 --- a/db/migrate/20120626013846_extract_distributor_and_supplier_address_to_spree_address.rb +++ b/db/migrate/20120626013846_extract_distributor_and_supplier_address_to_spree_address.rb @@ -1,4 +1,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migration + class Supplier < ActiveRecord::Base; end + class Distributor < ActiveRecord::Base; end + class Spree::Address < ActiveRecord::Base; end + + def up # -- Distributors add_column :distributors, :pickup_address_id, :integer diff --git a/db/migrate/20120626233350_rename_distributors_products_to_product_distributions.rb b/db/migrate/20120626233350_rename_distributors_products_to_product_distributions.rb index cca0850150..c2ecd94457 100644 --- a/db/migrate/20120626233350_rename_distributors_products_to_product_distributions.rb +++ b/db/migrate/20120626233350_rename_distributors_products_to_product_distributions.rb @@ -1,4 +1,7 @@ class RenameDistributorsProductsToProductDistributions < ActiveRecord::Migration + class Spree::ShippingMethod < ActiveRecord::Base; end + class ProductDistribution < ActiveRecord::Base; end + def up # Convert m2m join table into explicit join model, and add a shipping method relation and timestamps rename_table :distributors_products, :product_distributions @@ -9,7 +12,7 @@ class RenameDistributorsProductsToProductDistributions < ActiveRecord::Migration end # Set default shipping method on all product distributions - sm = Spree::ShippingMethod.first + sm = Spree::ShippingMethod.unscoped.first ProductDistribution.update_all(:shipping_method_id => sm.id) if sm end diff --git a/script/rails b/script/rails index f8da2cffd4..2edf3cdee5 100755 --- a/script/rails +++ b/script/rails @@ -1,6 +1,12 @@ #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. +if ENV['RAILS_ENV'] == 'test' + require 'simplecov' + SimpleCov.start 'rails' + puts "required simplecov" +end + APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb b/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb index 4ebf51e9ba..18b64986bf 100644 --- a/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb +++ b/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb @@ -160,7 +160,7 @@ module OpenFoodWeb applicator.send(:update_exchange, sender.id, receiver.id, {:variant_ids => [variant1.id, variant3.id]}) exchange.reload - exchange.variant_ids.should == [variant1.id, variant3.id] + exchange.variant_ids.sort.should == [variant1.id, variant3.id].sort applicator.send(:touched_exchanges).should == [exchange] end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c9cc0c868e..aaee9d2200 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,68 +1,60 @@ +require 'simplecov' +SimpleCov.start + require 'rubygems' -require 'spork' -#uncomment the following line to use spork with the debugger -#require 'spork/ext/ruby-debug' # By default, test on eaterprises deployment settings # This must be set before rails loads so that it's available in engine initializers ENV['OFW_DEPLOYMENT'] ||= 'eaterprises' -Spork.prefork do - ENV["RAILS_ENV"] ||= 'test' - require File.expand_path("../../config/environment", __FILE__) - require 'rspec/rails' - require 'rspec/autorun' - require 'capybara' - require 'database_cleaner' +ENV["RAILS_ENV"] = 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'capybara' +require 'database_cleaner' - # Requires supporting ruby files with custom matchers and macros, etc, - # in spec/support/ and its subdirectories. - Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} - require 'spree/core/testing_support/controller_requests' +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} +require 'spree/core/testing_support/controller_requests' - require 'active_record/fixtures' - fixtures_dir = File.expand_path('../../db/default', __FILE__) - ActiveRecord::Fixtures.create_fixtures(fixtures_dir, ['spree/states', 'spree/countries']) +require 'active_record/fixtures' +fixtures_dir = File.expand_path('../../db/default', __FILE__) +ActiveRecord::Fixtures.create_fixtures(fixtures_dir, ['spree/states', 'spree/countries']) - RSpec.configure do |config| - # ## Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - # - # config.mock_with :mocha - # config.mock_with :flexmock - # config.mock_with :rr +RSpec.configure do |config| + # ## Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. - config.use_transactional_fixtures = false + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = false - # If true, the base class of anonymous controllers will be inferred - # automatically. This will be the default behavior in future versions of - # rspec-rails. - config.infer_base_class_for_anonymous_controllers = false + # If true, the base class of anonymous controllers will be inferred + # automatically. This will be the default behavior in future versions of + # rspec-rails. + config.infer_base_class_for_anonymous_controllers = false - # ## Filters - # - config.filter_run_excluding :skip => true + # ## Filters + # + config.filter_run_excluding :skip => true - config.before(:each) do - if example.metadata[:js] - DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_states'] } - else - DatabaseCleaner.strategy = :transaction - end - DatabaseCleaner.start - end - - config.after(:each) do - DatabaseCleaner.clean + config.before(:each) do + if example.metadata[:js] + DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_states'] } + else + DatabaseCleaner.strategy = :transaction end config.before(:each) do @@ -74,18 +66,20 @@ Spork.prefork do config.include Spree::UrlHelpers config.include Spree::Core::TestingSupport::ControllerRequests, :type => :controller config.include Devise::TestHelpers, :type => :controller + + DatabaseCleaner.start end -end -Spork.each_run do - Dir["#{File.dirname(__FILE__)}/../app/**/*.rb"].each {|f| load f} - Dir["#{File.dirname(__FILE__)}/../lib/**/*.rb"].each {|f| load f} + config.after(:each) do + DatabaseCleaner.clean + end - Rails.application.reload_routes! + config.include Rails.application.routes.url_helpers + config.include Spree::UrlHelpers + config.include Spree::Core::TestingSupport::ControllerRequests, :type => :controller + config.include Devise::TestHelpers, :type => :controller + # Factory girl require 'factory_girl_rails' - - RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods - end + config.include FactoryGirl::Syntax::Methods end diff --git a/zeus.json b/zeus.json index 2ef8ae0046..3e075d6feb 100644 --- a/zeus.json +++ b/zeus.json @@ -13,7 +13,6 @@ "dbconsole": [] }, "test_environment": { - "cucumber_environment": {"cucumber": []}, "test_helper": {"test": ["rspec", "testrb"]} } }