ar-octopus-ruby-3 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +46 -0
  5. data/.rubocop_todo.yml +56 -0
  6. data/.travis.yml +18 -0
  7. data/Appraisals +16 -0
  8. data/Gemfile +4 -0
  9. data/README.mkdn +257 -0
  10. data/Rakefile +175 -0
  11. data/TODO.txt +7 -0
  12. data/ar-octopus.gemspec +44 -0
  13. data/gemfiles/rails42.gemfile +7 -0
  14. data/gemfiles/rails5.gemfile +7 -0
  15. data/gemfiles/rails51.gemfile +7 -0
  16. data/gemfiles/rails52.gemfile +7 -0
  17. data/lib/ar-octopus.rb +1 -0
  18. data/lib/octopus/abstract_adapter.rb +33 -0
  19. data/lib/octopus/association.rb +14 -0
  20. data/lib/octopus/association_shard_tracking.rb +74 -0
  21. data/lib/octopus/collection_association.rb +17 -0
  22. data/lib/octopus/collection_proxy.rb +16 -0
  23. data/lib/octopus/exception.rb +4 -0
  24. data/lib/octopus/finder_methods.rb +8 -0
  25. data/lib/octopus/load_balancing/round_robin.rb +20 -0
  26. data/lib/octopus/load_balancing.rb +4 -0
  27. data/lib/octopus/log_subscriber.rb +26 -0
  28. data/lib/octopus/migration.rb +236 -0
  29. data/lib/octopus/model.rb +216 -0
  30. data/lib/octopus/persistence.rb +45 -0
  31. data/lib/octopus/proxy.rb +399 -0
  32. data/lib/octopus/proxy_config.rb +251 -0
  33. data/lib/octopus/query_cache_for_shards.rb +24 -0
  34. data/lib/octopus/railtie.rb +11 -0
  35. data/lib/octopus/relation_proxy.rb +74 -0
  36. data/lib/octopus/result_patch.rb +19 -0
  37. data/lib/octopus/scope_proxy.rb +68 -0
  38. data/lib/octopus/shard_tracking/attribute.rb +22 -0
  39. data/lib/octopus/shard_tracking/dynamic.rb +11 -0
  40. data/lib/octopus/shard_tracking.rb +46 -0
  41. data/lib/octopus/singular_association.rb +9 -0
  42. data/lib/octopus/slave_group.rb +13 -0
  43. data/lib/octopus/version.rb +3 -0
  44. data/lib/octopus.rb +209 -0
  45. data/lib/tasks/octopus.rake +16 -0
  46. data/sample_app/.gitignore +4 -0
  47. data/sample_app/.rspec +1 -0
  48. data/sample_app/Gemfile +20 -0
  49. data/sample_app/Gemfile.lock +155 -0
  50. data/sample_app/README +3 -0
  51. data/sample_app/README.rdoc +261 -0
  52. data/sample_app/Rakefile +7 -0
  53. data/sample_app/app/assets/images/rails.png +0 -0
  54. data/sample_app/app/assets/javascripts/application.js +15 -0
  55. data/sample_app/app/assets/stylesheets/application.css +13 -0
  56. data/sample_app/app/controllers/application_controller.rb +4 -0
  57. data/sample_app/app/helpers/application_helper.rb +2 -0
  58. data/sample_app/app/mailers/.gitkeep +0 -0
  59. data/sample_app/app/models/.gitkeep +0 -0
  60. data/sample_app/app/models/item.rb +3 -0
  61. data/sample_app/app/models/user.rb +3 -0
  62. data/sample_app/app/views/layouts/application.html.erb +14 -0
  63. data/sample_app/autotest/discover.rb +2 -0
  64. data/sample_app/config/application.rb +62 -0
  65. data/sample_app/config/boot.rb +6 -0
  66. data/sample_app/config/cucumber.yml +8 -0
  67. data/sample_app/config/database.yml +28 -0
  68. data/sample_app/config/environment.rb +5 -0
  69. data/sample_app/config/environments/development.rb +37 -0
  70. data/sample_app/config/environments/production.rb +67 -0
  71. data/sample_app/config/environments/test.rb +37 -0
  72. data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
  73. data/sample_app/config/initializers/inflections.rb +15 -0
  74. data/sample_app/config/initializers/mime_types.rb +5 -0
  75. data/sample_app/config/initializers/secret_token.rb +7 -0
  76. data/sample_app/config/initializers/session_store.rb +8 -0
  77. data/sample_app/config/initializers/wrap_parameters.rb +14 -0
  78. data/sample_app/config/locales/en.yml +5 -0
  79. data/sample_app/config/routes.rb +58 -0
  80. data/sample_app/config/shards.yml +28 -0
  81. data/sample_app/config.ru +4 -0
  82. data/sample_app/db/migrate/20100720172715_create_users.rb +15 -0
  83. data/sample_app/db/migrate/20100720172730_create_items.rb +16 -0
  84. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +11 -0
  85. data/sample_app/db/schema.rb +29 -0
  86. data/sample_app/db/seeds.rb +16 -0
  87. data/sample_app/doc/README_FOR_APP +2 -0
  88. data/sample_app/features/migrate.feature +45 -0
  89. data/sample_app/features/seed.feature +15 -0
  90. data/sample_app/features/step_definitions/seeds_steps.rb +13 -0
  91. data/sample_app/features/step_definitions/web_steps.rb +218 -0
  92. data/sample_app/features/support/database.rb +13 -0
  93. data/sample_app/features/support/env.rb +57 -0
  94. data/sample_app/features/support/paths.rb +33 -0
  95. data/sample_app/lib/assets/.gitkeep +0 -0
  96. data/sample_app/lib/tasks/.gitkeep +0 -0
  97. data/sample_app/lib/tasks/cucumber.rake +64 -0
  98. data/sample_app/log/.gitkeep +0 -0
  99. data/sample_app/public/404.html +26 -0
  100. data/sample_app/public/422.html +26 -0
  101. data/sample_app/public/500.html +26 -0
  102. data/sample_app/public/favicon.ico +0 -0
  103. data/sample_app/public/images/rails.png +0 -0
  104. data/sample_app/public/index.html +279 -0
  105. data/sample_app/public/javascripts/application.js +2 -0
  106. data/sample_app/public/javascripts/controls.js +965 -0
  107. data/sample_app/public/javascripts/dragdrop.js +974 -0
  108. data/sample_app/public/javascripts/effects.js +1123 -0
  109. data/sample_app/public/javascripts/prototype.js +4874 -0
  110. data/sample_app/public/javascripts/rails.js +118 -0
  111. data/sample_app/public/robots.txt +5 -0
  112. data/sample_app/public/stylesheets/.gitkeep +0 -0
  113. data/sample_app/script/cucumber +10 -0
  114. data/sample_app/script/rails +6 -0
  115. data/sample_app/spec/models/item_spec.rb +5 -0
  116. data/sample_app/spec/models/user_spec.rb +5 -0
  117. data/sample_app/spec/spec_helper.rb +27 -0
  118. data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
  119. data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
  120. data/sample_app/vendor/plugins/.gitkeep +0 -0
  121. data/spec/config/shards.yml +231 -0
  122. data/spec/migrations/10_create_users_using_replication.rb +9 -0
  123. data/spec/migrations/11_add_field_in_all_slaves.rb +11 -0
  124. data/spec/migrations/12_create_users_using_block.rb +23 -0
  125. data/spec/migrations/13_create_users_using_block_and_using.rb +15 -0
  126. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +11 -0
  127. data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +9 -0
  128. data/spec/migrations/1_create_users_on_master.rb +9 -0
  129. data/spec/migrations/2_create_users_on_canada.rb +11 -0
  130. data/spec/migrations/3_create_users_on_both_shards.rb +11 -0
  131. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +11 -0
  132. data/spec/migrations/5_create_users_on_multiples_groups.rb +11 -0
  133. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +11 -0
  134. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +11 -0
  135. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +11 -0
  136. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +11 -0
  137. data/spec/octopus/association_shard_tracking_spec.rb +1036 -0
  138. data/spec/octopus/collection_proxy_spec.rb +16 -0
  139. data/spec/octopus/load_balancing/round_robin_spec.rb +15 -0
  140. data/spec/octopus/log_subscriber_spec.rb +19 -0
  141. data/spec/octopus/migration_spec.rb +151 -0
  142. data/spec/octopus/model_spec.rb +837 -0
  143. data/spec/octopus/octopus_spec.rb +123 -0
  144. data/spec/octopus/proxy_spec.rb +303 -0
  145. data/spec/octopus/query_cache_for_shards_spec.rb +40 -0
  146. data/spec/octopus/relation_proxy_spec.rb +132 -0
  147. data/spec/octopus/replicated_slave_grouped_spec.rb +91 -0
  148. data/spec/octopus/replication_spec.rb +196 -0
  149. data/spec/octopus/scope_proxy_spec.rb +97 -0
  150. data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +55 -0
  151. data/spec/octopus/sharded_spec.rb +33 -0
  152. data/spec/spec_helper.rb +18 -0
  153. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +15 -0
  154. data/spec/support/database_connection.rb +4 -0
  155. data/spec/support/database_models.rb +118 -0
  156. data/spec/support/octopus_helper.rb +66 -0
  157. data/spec/support/query_count.rb +17 -0
  158. data/spec/support/shared_contexts.rb +18 -0
  159. data/spec/tasks/octopus.rake_spec.rb +32 -0
  160. metadata +351 -0
@@ -0,0 +1,67 @@
1
+ SampleApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
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
19
+
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
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
39
+ # Use a different logger for distributed setups
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
+
42
+ # Use a different cache store in production
43
+ # config.cache_store = :mem_cache_store
44
+
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
+ # config.action_controller.asset_host = "http://assets.example.com"
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
+
51
+ # Disable delivery errors, bad email addresses will be ignored
52
+ # config.action_mailer.raise_delivery_errors = false
53
+
54
+ # Enable threaded mode
55
+ # config.threadsafe!
56
+
57
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
+ # the I18n.default_locale when a translation can not be found)
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
67
+ end
@@ -0,0 +1,37 @@
1
+ SampleApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
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
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!
8
+ config.cache_classes = true
9
+
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
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
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
37
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
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
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ SampleApp::Application.config.secret_token = '2bca6c53eb0b446425a9ae36b55b135d54867cfd039beb48ac8d8a8d4d2510f85c78a0280c5f193d8b3e0aaecc4fb09bc8fa3a805091c75fca3ec0deb47cff9b'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ SampleApp::Application.config.session_store :cookie_store, :key => '_sample_app_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
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
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,58 @@
1
+ SampleApp::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get :short
20
+ # post :toggle
21
+ # end
22
+ #
23
+ # collection do
24
+ # get :sold
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get :recent, :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end
@@ -0,0 +1,28 @@
1
+ octopus:
2
+ environments:
3
+ - development
4
+ - test
5
+ development:
6
+ asia:
7
+ adapter: sqlite3
8
+ database: db/asia.sqlite3
9
+ europe:
10
+ adapter: sqlite3
11
+ database: db/europe.sqlite3
12
+ america:
13
+ adapter: sqlite3
14
+ database: db/america.sqlite3
15
+
16
+ test:
17
+ asia:
18
+ adapter: sqlite3
19
+ database: db/asia.sqlite3
20
+ europe:
21
+ adapter: sqlite3
22
+ database: db/europe.sqlite3
23
+ america:
24
+ adapter: sqlite3
25
+ database: db/america.sqlite3
26
+ dev_env:
27
+ adapter: sqlite3
28
+ database: db/development.sqlite3
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run SampleApp::Application
@@ -0,0 +1,15 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ using(:master, :asia, :europe, :america)
3
+
4
+ def self.up
5
+ create_table :users do |t|
6
+ t.string :name
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :users
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ class CreateItems < ActiveRecord::Migration
2
+ using(:master, :asia, :europe, :america)
3
+
4
+ def self.up
5
+ create_table :items do |t|
6
+ t.string :name
7
+ t.integer :user_id
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :items
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSampleUsers < ActiveRecord::Migration
2
+ using(:master, :asia, :europe, :america)
3
+
4
+ def self.up
5
+ User.create!(:name => 'Exception')
6
+ end
7
+
8
+ def self.down
9
+ User.find_by_name('Exception').delete
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20_100_720_210_335) do
15
+
16
+ create_table 'items', :force => true do |t|
17
+ t.string 'name'
18
+ t.integer 'user_id'
19
+ t.datetime 'created_at', :null => false
20
+ t.datetime 'updated_at', :null => false
21
+ end
22
+
23
+ create_table 'users', :force => true do |t|
24
+ t.string 'name'
25
+ t.datetime 'created_at', :null => false
26
+ t.datetime 'updated_at', :null => false
27
+ end
28
+
29
+ end
@@ -0,0 +1,16 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Mayor.create(:name => 'Daley', :city => cities.first)
8
+ Octopus.using(:asia) do
9
+ User.create!(:name => 'Asia User')
10
+ end
11
+
12
+ Octopus.using(:america) do
13
+ User.create([{ :name => 'America User 1' }, { :name => 'America User 2' }])
14
+ end
15
+
16
+ User.create!(:name => 'Teste')
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
@@ -0,0 +1,45 @@
1
+ Feature: rake db:migrate
2
+ In order move data along shards
3
+ As a developer
4
+ I want to use the rake db:migrate command
5
+
6
+ Scenario: db:migrate should work with octopus
7
+ When I run inside my Rails project "rake db:migrate" with enviroment "development"
8
+ Then the output should contain "CreateUsers: migrating - Shard: master"
9
+ Then the output should contain "CreateUsers: migrating - Shard: asia"
10
+ Then the output should contain "CreateUsers: migrating - Shard: europe"
11
+ Then the output should contain "CreateUsers: migrating - Shard: america"
12
+
13
+ Scenario: db:migrate:redo should work with octopus
14
+ When I run inside my Rails project "rake db:migrate VERSION=20100720172715" with enviroment "development"
15
+ When I run inside my Rails project "rake db:migrate VERSION=20100720172730" with enviroment "development"
16
+ When I run inside my Rails project "rake db:migrate:redo" with enviroment "development"
17
+ Then the output should contain "CreateItems: reverting - Shard: master"
18
+ Then the output should contain "CreateItems: reverting - Shard: asia"
19
+ Then the output should contain "CreateItems: reverting - Shard: europe"
20
+ Then the output should contain "CreateItems: reverting - Shard: america"
21
+ Then the output should contain "CreateItems: migrating - Shard: master"
22
+ Then the output should contain "CreateItems: migrating - Shard: asia"
23
+ Then the output should contain "CreateItems: migrating - Shard: europe"
24
+ Then the output should contain "CreateItems: migrating - Shard: america"
25
+
26
+ Scenario: db:migrate finishing the migration
27
+ When I run inside my Rails project "rake db:migrate" with enviroment "development"
28
+ Then the output should contain "CreateSampleUsers: migrating - Shard: america"
29
+ Then the output should contain "CreateSampleUsers: migrating - Shard: master"
30
+ Then the output should contain "CreateSampleUsers: migrating - Shard: asia"
31
+ Then the output should contain "CreateSampleUsers: migrating - Shard: europe"
32
+ Then the output should not contain "An error has occurred, this and all later migrations canceled:"
33
+ Then the version of "dev_env" shard should be "20100720210335"
34
+ Then the version of "america" shard should be "nil"
35
+ Then the version of "europe" shard should be "nil"
36
+ Then the version of "asia" shard should be "nil"
37
+
38
+ Scenario: after running rake db:migrate
39
+ When I run inside my Rails project "rake db:abort_if_pending_migrations" with enviroment "development"
40
+ Then the output should contain "pending migrations"
41
+ When I run inside my Rails project "rake db:migrate" with enviroment "development"
42
+ When I run inside my Rails project "rake db:abort_if_pending_migrations RAILS_ENV=development" with enviroment "development"
43
+ Then the output should not contain "pending migrations"
44
+
45
+
@@ -0,0 +1,15 @@
1
+ Feature: rake db:seed
2
+ In order to create sample records in the database
3
+ As a developer
4
+ I want to use the rake db:seed command
5
+
6
+ Scenario: db:seed should fail
7
+ When I run inside my Rails project "rake db:seed" with enviroment "development"
8
+ Then the output should contain "pending migrations"
9
+
10
+ Scenario: db:seed should work with octopus
11
+ When I run inside my Rails project "rake db:migrate" with enviroment "development"
12
+ When I run inside my Rails project "rake db:seed" with enviroment "development"
13
+ Then the "asia" shard should have one user named "Asia User"
14
+ Then the "america" shard should have one user named "America User 1"
15
+ Then the "america" shard should have one user named "America User 2"
@@ -0,0 +1,13 @@
1
+ Then /^the "([^"]*)" shard should have one user named "([^"]*)"$/ do |shard_name, user_name|
2
+ User.using(shard_name.to_sym).where(:name => user_name).count.should == 1
3
+ end
4
+
5
+ Then /^the version of "([^"]*)" shard should be "([^"]*)"$/ do |shard_name, version|
6
+ ab = ActiveRecord::Base.using(shard_name.to_sym).connection.select_value('select * from schema_migrations order by version desc limit 1;')
7
+ version = '' if version == 'nil'
8
+ ab.to_s.should == version
9
+ end
10
+
11
+ When /^I run inside my Rails project "([^"]*)" with enviroment "([^"]*)"$/ do |command, enviroment|
12
+ run("cd #{Rails.root} && RAILS_ENV=#{enviroment} #{command}")
13
+ end
@@ -0,0 +1,218 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+ require 'uri'
8
+ require 'cgi'
9
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'support', 'paths'))
10
+
11
+ module WithinHelpers
12
+ def with_scope(locator)
13
+ locator ? within(locator) { yield } : yield
14
+ end
15
+ end
16
+ World(WithinHelpers)
17
+
18
+ Given /^(?:|I )am on (.+)$/ do |page_name|
19
+ visit path_to(page_name)
20
+ end
21
+
22
+ When /^(?:|I )go to (.+)$/ do |page_name|
23
+ visit path_to(page_name)
24
+ end
25
+
26
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
27
+ with_scope(selector) do
28
+ click_button(button)
29
+ end
30
+ end
31
+
32
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
33
+ with_scope(selector) do
34
+ click_link(link)
35
+ end
36
+ end
37
+
38
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
39
+ with_scope(selector) do
40
+ fill_in(field, :with => value)
41
+ end
42
+ end
43
+
44
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
45
+ with_scope(selector) do
46
+ fill_in(field, :with => value)
47
+ end
48
+ end
49
+
50
+ # Use this to fill in an entire form with data from a table. Example:
51
+ #
52
+ # When I fill in the following:
53
+ # | Account Number | 5002 |
54
+ # | Expiry date | 2009-11-01 |
55
+ # | Note | Nice guy |
56
+ # | Wants Email? | |
57
+ #
58
+ # TODO: Add support for checkbox, select og option
59
+ # based on naming conventions.
60
+ #
61
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
62
+ with_scope(selector) do
63
+ fields.rows_hash.each do |name, value|
64
+ When %(I fill in "#{name}" with "#{value}")
65
+ end
66
+ end
67
+ end
68
+
69
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
70
+ with_scope(selector) do
71
+ select(value, :from => field)
72
+ end
73
+ end
74
+
75
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
76
+ with_scope(selector) do
77
+ check(field)
78
+ end
79
+ end
80
+
81
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
82
+ with_scope(selector) do
83
+ uncheck(field)
84
+ end
85
+ end
86
+
87
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
88
+ with_scope(selector) do
89
+ choose(field)
90
+ end
91
+ end
92
+
93
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
94
+ with_scope(selector) do
95
+ attach_file(field, path)
96
+ end
97
+ end
98
+
99
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
100
+ require 'json'
101
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
102
+ actual = JSON.pretty_generate(JSON.parse(response.body))
103
+ expected.should == actual
104
+ end
105
+
106
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
107
+ with_scope(selector) do
108
+ if page.respond_to? :should
109
+ page.should have_content(text)
110
+ else
111
+ assert page.has_content?(text)
112
+ end
113
+ end
114
+ end
115
+
116
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
117
+ regexp = Regexp.new(regexp)
118
+ with_scope(selector) do
119
+ if page.respond_to? :should
120
+ page.should have_xpath('//*', :text => regexp)
121
+ else
122
+ assert page.has_xpath?('//*', :text => regexp)
123
+ end
124
+ end
125
+ end
126
+
127
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
128
+ with_scope(selector) do
129
+ if page.respond_to? :should
130
+ page.should have_no_content(text)
131
+ else
132
+ assert page.has_no_content?(text)
133
+ end
134
+ end
135
+ end
136
+
137
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
138
+ regexp = Regexp.new(regexp)
139
+ with_scope(selector) do
140
+ if page.respond_to? :should
141
+ page.should have_no_xpath('//*', :text => regexp)
142
+ else
143
+ assert page.has_no_xpath?('//*', :text => regexp)
144
+ end
145
+ end
146
+ end
147
+
148
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
149
+ with_scope(selector) do
150
+ field = find_field(field)
151
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
152
+ if field_value.respond_to? :should
153
+ field_value.should =~ /#{value}/
154
+ else
155
+ assert_match(/#{value}/, field_value)
156
+ end
157
+ end
158
+ end
159
+
160
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
161
+ with_scope(selector) do
162
+ field = find_field(field)
163
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
164
+ if field_value.respond_to? :should_not
165
+ field_value.should_not =~ /#{value}/
166
+ else
167
+ assert_no_match(/#{value}/, field_value)
168
+ end
169
+ end
170
+ end
171
+
172
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
173
+ with_scope(selector) do
174
+ field_checked = find_field(label)['checked']
175
+ if field_checked.respond_to? :should
176
+ field_checked.should be_true
177
+ else
178
+ assert field_checked
179
+ end
180
+ end
181
+ end
182
+
183
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
184
+ with_scope(selector) do
185
+ field_checked = find_field(label)['checked']
186
+ if field_checked.respond_to? :should
187
+ field_checked.should be_false
188
+ else
189
+ assert !field_checked
190
+ end
191
+ end
192
+ end
193
+
194
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
195
+ current_path = URI.parse(current_url).path
196
+ if current_path.respond_to? :should
197
+ current_path.should == path_to(page_name)
198
+ else
199
+ assert_equal path_to(page_name), current_path
200
+ end
201
+ end
202
+
203
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
204
+ query = URI.parse(current_url).query
205
+ actual_params = query ? CGI.parse(query) : {}
206
+ expected_params = {}
207
+ expected_pairs.rows_hash.each_pair { |k, v| expected_params[k] = v.split(',') }
208
+
209
+ if actual_params.respond_to? :should
210
+ actual_params.should == expected_params
211
+ else
212
+ assert_equal expected_params, actual_params
213
+ end
214
+ end
215
+
216
+ Then /^show me the page$/ do
217
+ save_and_open_page
218
+ end