ar-octopus 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +7 -6
  3. data/README.mkdn +1 -1
  4. data/Rakefile +21 -1
  5. data/gemfiles/rails30.gemfile +8 -0
  6. data/gemfiles/rails31.gemfile +7 -0
  7. data/gemfiles/rails32.gemfile +7 -0
  8. data/lib/octopus.rb +4 -1
  9. data/lib/octopus/model.rb +15 -0
  10. data/lib/octopus/version.rb +1 -1
  11. data/sample_app/Gemfile +9 -10
  12. data/sample_app/README.rdoc +261 -0
  13. data/sample_app/Rakefile +2 -2
  14. data/sample_app/app/assets/images/rails.png +0 -0
  15. data/sample_app/app/assets/javascripts/application.js +15 -0
  16. data/sample_app/app/assets/stylesheets/application.css +13 -0
  17. data/sample_app/app/mailers/.gitkeep +0 -0
  18. data/sample_app/app/models/.gitkeep +0 -0
  19. data/sample_app/config/application.rb +30 -14
  20. data/sample_app/config/boot.rb +3 -10
  21. data/sample_app/config/database.yml +18 -15
  22. data/sample_app/config/environments/development.rb +22 -4
  23. data/sample_app/config/environments/production.rb +35 -14
  24. data/sample_app/config/environments/test.rb +13 -8
  25. data/sample_app/config/initializers/inflections.rb +5 -0
  26. data/sample_app/config/initializers/secret_token.rb +1 -1
  27. data/sample_app/config/initializers/session_store.rb +3 -3
  28. data/sample_app/config/initializers/wrap_parameters.rb +14 -0
  29. data/sample_app/config/locales/en.yml +1 -1
  30. data/sample_app/config/routes.rb +1 -1
  31. data/sample_app/db/schema.rb +7 -8
  32. data/sample_app/features/support/database.rb +13 -0
  33. data/sample_app/features/support/env.rb +43 -58
  34. data/sample_app/lib/assets/.gitkeep +0 -0
  35. data/sample_app/lib/tasks/cucumber.rake +15 -3
  36. data/sample_app/log/.gitkeep +0 -0
  37. data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
  38. data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
  39. data/spec/octopus/association_spec.rb +1 -1
  40. data/spec/octopus/octopus_spec.rb +4 -4
  41. data/spec/octopus/proxy_spec.rb +40 -7
  42. data/spec/octopus/replication_spec.rb +1 -1
  43. data/spec/octopus/sharded_spec.rb +1 -1
  44. data/spec/spec_helper.rb +0 -2
  45. data/spec/support/database_models.rb +21 -0
  46. data/spec/support/octopus_helper.rb +7 -1
  47. metadata +175 -156
  48. data/sample_app/test/performance/browsing_test.rb +0 -9
  49. data/sample_app/test/test_helper.rb +0 -13
@@ -1,7 +1,7 @@
1
+ #!/usr/bin/env rake
1
2
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
3
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
4
 
4
5
  require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
6
 
7
- Rails::Application.load_tasks
7
+ SampleApp::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
File without changes
File without changes
@@ -2,9 +2,12 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- # If you have a Gemfile, require the gems listed there, including any gems
6
- # you've limited to :test, :development, or :production.
7
- Bundler.require(:default, Rails.env) if defined?(Bundler)
5
+ if defined?(Bundler)
6
+ # If you precompile assets before deploying to production, use this line
7
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
8
+ # If you want your assets lazily compiled in production, use this line
9
+ # Bundler.require(:default, :assets, Rails.env)
10
+ end
8
11
 
9
12
  module SampleApp
10
13
  class Application < Rails::Application
@@ -12,14 +15,14 @@ module SampleApp
12
15
  # Application configuration should go into files in config/initializers
13
16
  # -- all .rb files in that directory are automatically loaded.
14
17
 
15
- # Add additional load paths for your own custom dirs
16
- # config.load_paths += %W( #{config.root}/extras )
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
17
20
 
18
21
  # Only load the plugins named here, in the order given (default is alphabetical).
19
- # :all can be used as a placeholder for all plugins not explicitly named
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
23
  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
24
 
22
- # Activate observers that should always be running
25
+ # Activate observers that should always be running.
23
26
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
27
 
25
28
  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
@@ -30,17 +33,30 @@ module SampleApp
30
33
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
34
  # config.i18n.default_locale = :de
32
35
 
33
- # Configure generators values. Many other options are available, be sure to check the documentation.
34
- # config.generators do |g|
35
- # g.orm :active_record
36
- # g.template_engine :erb
37
- # g.test_framework :test_unit, :fixture => true
38
- # end
39
-
40
36
  # Configure the default encoding used in templates for Ruby 1.9.
41
37
  config.encoding = "utf-8"
42
38
 
43
39
  # Configure sensitive parameters which will be filtered from the log file.
44
40
  config.filter_parameters += [:password]
41
+
42
+ # Enable escaping HTML in JSON.
43
+ config.active_support.escape_html_entities_in_json = true
44
+
45
+ # Use SQL instead of Active Record's schema dumper when creating the database.
46
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
47
+ # like if you have constraints or database-specific column types
48
+ # config.active_record.schema_format = :sql
49
+
50
+ # Enforce whitelist mode for mass assignment.
51
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
52
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
53
+ # parameters by using an attr_accessible or attr_protected declaration.
54
+ config.active_record.whitelist_attributes = true
55
+
56
+ # Enable the asset pipeline
57
+ config.assets.enabled = true
58
+
59
+ # Version of your assets, change this if you want to expire all your assets
60
+ config.assets.version = '1.0'
45
61
  end
46
62
  end
@@ -1,13 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
3
  # Set up gems listed in the Gemfile.
4
- gemfile = File.expand_path('../../Gemfile', __FILE__)
5
- begin
6
- ENV['BUNDLE_GEMFILE'] = gemfile
7
- require 'bundler'
8
- Bundler.setup
9
- rescue Bundler::GemNotFound => e
10
- STDERR.puts e.message
11
- STDERR.puts "Try running `bundle install`."
12
- exit!
13
- end if File.exist?(gemfile)
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -1,25 +1,28 @@
1
1
  # SQLite version 3.x
2
2
  # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
3
  development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
4
+ adapter: postgresql
5
+ username: postgres
6
+ password:
7
+ database: octopus_sample_app_development
8
+ encoding: unicode
9
+ host: localhost
8
10
 
9
11
  # Warning: The database defined as "test" will be erased and
10
12
  # re-generated from your development database when you run "rake".
11
13
  # Do not set this db to the same as development or production.
12
14
  test: &test
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
15
+ adapter: postgresql
16
+ username: postgres
17
+ password:
18
+ database: octopus_sample_app_test
19
+ encoding: unicode
20
+ host: localhost
17
21
 
18
22
  production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
23
-
24
- cucumber:
25
- <<: *test
23
+ adapter: postgresql
24
+ username: postgres
25
+ password:
26
+ database: octopus_sample_app_production
27
+ encoding: unicode
28
+ host: localhost
@@ -1,9 +1,9 @@
1
1
  SampleApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.rb
2
+ # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
4
  # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
9
  # Log error messages when you accidentally call methods on nil.
@@ -11,9 +11,27 @@ SampleApp::Application.configure do
11
11
 
12
12
  # Show full error reports and disable caching
13
13
  config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
14
  config.action_controller.perform_caching = false
16
15
 
17
16
  # Don't care if the mailer can't send
18
17
  config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
19
37
  end
@@ -1,7 +1,6 @@
1
1
  SampleApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.rb
2
+ # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
- # The production environment is meant for finished, "live" apps.
5
4
  # Code is not reloaded between requests
6
5
  config.cache_classes = true
7
6
 
@@ -9,31 +8,46 @@ SampleApp::Application.configure do
9
8
  config.consider_all_requests_local = false
10
9
  config.action_controller.perform_caching = true
11
10
 
12
- # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
14
19
 
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to nil and saved in location specified by config.assets.prefix
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
17
29
 
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
20
32
 
21
33
  # See everything in the log (default is :info)
22
34
  # config.log_level = :debug
23
35
 
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
24
39
  # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
26
41
 
27
42
  # Use a different cache store in production
28
43
  # config.cache_store = :mem_cache_store
29
44
 
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
- config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
35
46
  # config.action_controller.asset_host = "http://assets.example.com"
36
47
 
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
37
51
  # Disable delivery errors, bad email addresses will be ignored
38
52
  # config.action_mailer.raise_delivery_errors = false
39
53
 
@@ -43,4 +57,11 @@ SampleApp::Application.configure do
43
57
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
58
  # the I18n.default_locale when a translation can not be found)
45
59
  config.i18n.fallbacks = true
60
+
61
+ # Send deprecation notices to registered listeners
62
+ config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
46
67
  end
@@ -1,13 +1,17 @@
1
1
  SampleApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.rb
2
+ # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
4
  # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
5
+ # test suite. You never need to work with it otherwise. Remember that
6
6
  # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
7
+ # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
- # Log error messages when you accidentally call methods on nil.
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
11
15
  config.whiny_nils = true
12
16
 
13
17
  # Show full error reports and disable caching
@@ -25,8 +29,9 @@ SampleApp::Application.configure do
25
29
  # ActionMailer::Base.deliveries array.
26
30
  config.action_mailer.delivery_method = :test
27
31
 
28
- # Use SQL instead of Active Record's schema dumper when creating the test database.
29
- # This is necessary if your schema can't be completely dumped by the schema dumper,
30
- # like if you have constraints or database-specific column types
31
- # config.active_record.schema_format = :sql
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
32
37
  end
@@ -8,3 +8,8 @@
8
8
  # inflect.irregular 'person', 'people'
9
9
  # inflect.uncountable %w( fish sheep )
10
10
  # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Rails.application.config.secret_token = '1b60fd7d627c1749f508e1578d14555c4c2122a8988e34f94c8e9dbe62df7f688462445badf79594a193542a32d0b1fdbfdf2c42539e212cbf6ad9b1c769c6f6'
7
+ SampleApp::Application.config.secret_token = '2bca6c53eb0b446425a9ae36b55b135d54867cfd039beb48ac8d8a8d4d2510f85c78a0280c5f193d8b3e0aaecc4fb09bc8fa3a805091c75fca3ec0deb47cff9b'
@@ -1,8 +1,8 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.session_store :cookie_store, :key => '_sample_app_session'
3
+ SampleApp::Application.config.session_store :cookie_store, key: '_sample_app_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rake db:sessions:create")
8
- # Rails.application.config.session_store :active_record_store
7
+ # (create the session table with "rails generate session_migration")
8
+ # SampleApp::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -1,5 +1,5 @@
1
1
  # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
5
  hello: "Hello world"
@@ -1,4 +1,4 @@
1
- SampleApp::Application.routes.draw do |map|
1
+ SampleApp::Application.routes.draw do
2
2
  # The priority is based upon order of creation:
3
3
  # first created -> highest priority.
4
4
 
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  # This file is auto-generated from the current state of the database. Instead
2
3
  # of editing this file, please use the migrations feature of Active Record to
3
4
  # incrementally modify your database, and then regenerate this schema definition.
@@ -12,19 +13,17 @@
12
13
 
13
14
  ActiveRecord::Schema.define(:version => 20100720210335) do
14
15
 
15
- create_table "items", :id => false, :force => true do |t|
16
- t.integer "id", :null => false
16
+ create_table "items", :force => true do |t|
17
17
  t.string "name"
18
18
  t.integer "user_id"
19
- t.datetime "created_at"
20
- t.datetime "updated_at"
19
+ t.datetime "created_at", :null => false
20
+ t.datetime "updated_at", :null => false
21
21
  end
22
22
 
23
- create_table "users", :id => false, :force => true do |t|
24
- t.integer "id", :null => false
23
+ create_table "users", :force => true do |t|
25
24
  t.string "name"
26
- t.datetime "created_at"
27
- t.datetime "updated_at"
25
+ t.datetime "created_at", :null => false
26
+ t.datetime "updated_at", :null => false
28
27
  end
29
28
 
30
29
  end
@@ -0,0 +1,13 @@
1
+ After do
2
+ `rm #{Rails.root.to_s}/db/america.sqlite3`
3
+ `rm #{Rails.root.to_s}/db/asia.sqlite3`
4
+ `rm #{Rails.root.to_s}/db/development.sqlite3`
5
+ `rm #{Rails.root.to_s}/db/europe.sqlite3`
6
+ end
7
+
8
+ Before do
9
+ `rm #{Rails.root.to_s}/db/america.sqlite3`
10
+ `rm #{Rails.root.to_s}/db/asia.sqlite3`
11
+ `rm #{Rails.root.to_s}/db/development.sqlite3`
12
+ `rm #{Rails.root.to_s}/db/europe.sqlite3`
13
+ end
@@ -4,70 +4,55 @@
4
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
7
- ENV["RAILS_ENV"] ||= "test"
8
- require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
7
+ require 'cucumber/rails'
9
8
 
10
- require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
11
- require 'cucumber/rails/rspec'
12
- require 'cucumber/rails/world'
13
- require 'cucumber/rails/active_record'
14
- require 'cucumber/web/tableish'
9
+ # Capybara defaults to CSS3 selectors rather than XPath.
10
+ # If you'd prefer to use XPath, just uncomment this line and adjust any
11
+ # selectors in your step definitions to use the XPath syntax.
12
+ # Capybara.default_selector = :xpath
15
13
 
16
- require 'capybara/rails'
17
- require 'capybara/cucumber'
18
- require 'capybara/session'
19
- require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
20
- require 'aruba/cucumber'
21
- # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
22
- # order to ease the transition to Capybara we set the default here. If you'd
23
- # prefer to use XPath just remove this line and adjust any selectors in your
24
- # steps to use the XPath syntax.
25
- Capybara.default_selector = :css
26
-
27
- # If you set this to false, any error raised from within your app will bubble
28
- # up to your step definition and out to cucumber unless you catch it somewhere
29
- # on the way. You can make Rails rescue errors and render error pages on a
30
- # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
14
+ # By default, any exception happening in your Rails application will bubble up
15
+ # to Cucumber so that your scenario will fail. This is a different from how
16
+ # your application behaves in the production environment, where an error page will
17
+ # be rendered instead.
18
+ #
19
+ # Sometimes we want to override this default behaviour and allow Rails to rescue
20
+ # exceptions and display an error page (just like when the app is running in production).
21
+ # Typical scenarios where you want to do this is when you test your error pages.
22
+ # There are two ways to allow Rails to rescue exceptions:
23
+ #
24
+ # 1) Tag your scenario (or feature) with @allow-rescue
25
+ #
26
+ # 2) Set the value below to true. Beware that doing this globally is not
27
+ # recommended as it will mask a lot of errors for you!
31
28
  #
32
- # If you set this to true, Rails will rescue all errors and render error
33
- # pages, more or less in the same way your application would behave in the
34
- # default production environment. It's not recommended to do this for all
35
- # of your scenarios, as this makes it hard to discover errors in your application.
36
29
  ActionController::Base.allow_rescue = false
37
30
 
38
- # If you set this to true, each scenario will run in a database transaction.
39
- # You can still turn off transactions on a per-scenario basis, simply tagging
40
- # a feature or scenario with the @no-txn tag. If you are using Capybara,
41
- # tagging with @culerity or @javascript will also turn transactions off.
31
+ # Remove/comment out the lines below if your app doesn't have a database.
32
+ # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
33
+ begin
34
+ DatabaseCleaner.strategy = :transaction
35
+ rescue NameError
36
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
37
+ end
38
+
39
+ # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
40
+ # See the DatabaseCleaner documentation for details. Example:
42
41
  #
43
- # If you set this to false, transactions will be off for all scenarios,
44
- # regardless of whether you use @no-txn or not.
42
+ # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
43
+ # # { :except => [:widgets] } may not do what you expect here
44
+ # # as Cucumber::Rails::Database.javascript_strategy overrides
45
+ # # this setting.
46
+ # DatabaseCleaner.strategy = :truncation
47
+ # end
48
+ #
49
+ # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
50
+ # DatabaseCleaner.strategy = :transaction
51
+ # end
45
52
  #
46
- # Beware that turning transactions off will leave data in your database
47
- # after each scenario, which can lead to hard-to-debug failures in
48
- # subsequent scenarios. If you do this, we recommend you create a Before
49
- # block that will explicitly put your database in a known state.
50
- Cucumber::Rails::World.use_transactional_fixtures = true
51
- # How to clean your database when transactions are turned off. See
52
- # http://github.com/bmabey/database_cleaner for more info.
53
- if defined?(ActiveRecord::Base)
54
- begin
55
- require 'database_cleaner'
56
- DatabaseCleaner.strategy = :truncation
57
- rescue LoadError => ignore_if_database_cleaner_not_present
58
- end
59
- end
60
53
 
61
- After do
62
- `rm #{Rails.root.to_s}/db/america.sqlite3`
63
- `rm #{Rails.root.to_s}/db/asia.sqlite3`
64
- `rm #{Rails.root.to_s}/db/development.sqlite3`
65
- `rm #{Rails.root.to_s}/db/europe.sqlite3`
66
- end
54
+ # Possible values are :truncation and :transaction
55
+ # The :transaction strategy is faster, but might give you threading problems.
56
+ # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
57
+ Cucumber::Rails::Database.javascript_strategy = :truncation
67
58
 
68
- Before do
69
- `rm #{Rails.root.to_s}/db/america.sqlite3`
70
- `rm #{Rails.root.to_s}/db/asia.sqlite3`
71
- `rm #{Rails.root.to_s}/db/development.sqlite3`
72
- `rm #{Rails.root.to_s}/db/europe.sqlite3`
73
- end