misha-ar-octopus 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/.rubocop_todo.yml +56 -0
- data/.ruby-version +1 -0
- data/.travis.yml +18 -0
- data/Appraisals +16 -0
- data/Gemfile +4 -0
- data/README.mkdn +242 -0
- data/Rakefile +172 -0
- data/TODO.txt +7 -0
- data/ar-octopus.gemspec +42 -0
- data/gemfiles/rails32.gemfile +7 -0
- data/gemfiles/rails4.gemfile +7 -0
- data/gemfiles/rails41.gemfile +7 -0
- data/gemfiles/rails42.gemfile +7 -0
- data/init.rb +1 -0
- data/lib/ar-octopus.rb +1 -0
- data/lib/octopus.rb +181 -0
- data/lib/octopus/abstract_adapter.rb +35 -0
- data/lib/octopus/association.rb +13 -0
- data/lib/octopus/association_shard_tracking.rb +114 -0
- data/lib/octopus/collection_association.rb +11 -0
- data/lib/octopus/collection_proxy.rb +16 -0
- data/lib/octopus/exception.rb +4 -0
- data/lib/octopus/has_and_belongs_to_many_association.rb +9 -0
- data/lib/octopus/load_balancing.rb +4 -0
- data/lib/octopus/load_balancing/round_robin.rb +20 -0
- data/lib/octopus/log_subscriber.rb +22 -0
- data/lib/octopus/migration.rb +168 -0
- data/lib/octopus/model.rb +210 -0
- data/lib/octopus/persistence.rb +39 -0
- data/lib/octopus/proxy.rb +534 -0
- data/lib/octopus/railtie.rb +11 -0
- data/lib/octopus/relation_proxy.rb +35 -0
- data/lib/octopus/scope_proxy.rb +61 -0
- data/lib/octopus/shard_tracking.rb +41 -0
- data/lib/octopus/shard_tracking/attribute.rb +22 -0
- data/lib/octopus/shard_tracking/dynamic.rb +11 -0
- data/lib/octopus/singular_association.rb +9 -0
- data/lib/octopus/slave_group.rb +13 -0
- data/lib/octopus/version.rb +3 -0
- data/lib/tasks/octopus.rake +16 -0
- data/rails/init.rb +1 -0
- data/sample_app/.gitignore +4 -0
- data/sample_app/.rspec +1 -0
- data/sample_app/Gemfile +20 -0
- data/sample_app/README +3 -0
- data/sample_app/README.rdoc +261 -0
- data/sample_app/Rakefile +7 -0
- data/sample_app/app/assets/images/rails.png +0 -0
- data/sample_app/app/assets/javascripts/application.js +15 -0
- data/sample_app/app/assets/stylesheets/application.css +13 -0
- data/sample_app/app/controllers/application_controller.rb +4 -0
- data/sample_app/app/helpers/application_helper.rb +2 -0
- data/sample_app/app/mailers/.gitkeep +0 -0
- data/sample_app/app/models/.gitkeep +0 -0
- data/sample_app/app/models/item.rb +3 -0
- data/sample_app/app/models/user.rb +3 -0
- data/sample_app/app/views/layouts/application.html.erb +14 -0
- data/sample_app/autotest/discover.rb +2 -0
- data/sample_app/config.ru +4 -0
- data/sample_app/config/application.rb +62 -0
- data/sample_app/config/boot.rb +6 -0
- data/sample_app/config/cucumber.yml +8 -0
- data/sample_app/config/database.yml +28 -0
- data/sample_app/config/environment.rb +5 -0
- data/sample_app/config/environments/development.rb +37 -0
- data/sample_app/config/environments/production.rb +67 -0
- data/sample_app/config/environments/test.rb +37 -0
- data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
- data/sample_app/config/initializers/inflections.rb +15 -0
- data/sample_app/config/initializers/mime_types.rb +5 -0
- data/sample_app/config/initializers/secret_token.rb +7 -0
- data/sample_app/config/initializers/session_store.rb +8 -0
- data/sample_app/config/initializers/wrap_parameters.rb +14 -0
- data/sample_app/config/locales/en.yml +5 -0
- data/sample_app/config/routes.rb +58 -0
- data/sample_app/config/shards.yml +28 -0
- data/sample_app/db/migrate/20100720172715_create_users.rb +15 -0
- data/sample_app/db/migrate/20100720172730_create_items.rb +16 -0
- data/sample_app/db/migrate/20100720210335_create_sample_users.rb +11 -0
- data/sample_app/db/schema.rb +29 -0
- data/sample_app/db/seeds.rb +16 -0
- data/sample_app/doc/README_FOR_APP +2 -0
- data/sample_app/features/migrate.feature +45 -0
- data/sample_app/features/seed.feature +15 -0
- data/sample_app/features/step_definitions/seeds_steps.rb +13 -0
- data/sample_app/features/step_definitions/web_steps.rb +218 -0
- data/sample_app/features/support/database.rb +13 -0
- data/sample_app/features/support/env.rb +57 -0
- data/sample_app/features/support/paths.rb +33 -0
- data/sample_app/lib/assets/.gitkeep +0 -0
- data/sample_app/lib/tasks/.gitkeep +0 -0
- data/sample_app/lib/tasks/cucumber.rake +64 -0
- data/sample_app/log/.gitkeep +0 -0
- data/sample_app/public/404.html +26 -0
- data/sample_app/public/422.html +26 -0
- data/sample_app/public/500.html +26 -0
- data/sample_app/public/favicon.ico +0 -0
- data/sample_app/public/images/rails.png +0 -0
- data/sample_app/public/index.html +279 -0
- data/sample_app/public/javascripts/application.js +2 -0
- data/sample_app/public/javascripts/controls.js +965 -0
- data/sample_app/public/javascripts/dragdrop.js +974 -0
- data/sample_app/public/javascripts/effects.js +1123 -0
- data/sample_app/public/javascripts/prototype.js +4874 -0
- data/sample_app/public/javascripts/rails.js +118 -0
- data/sample_app/public/robots.txt +5 -0
- data/sample_app/public/stylesheets/.gitkeep +0 -0
- data/sample_app/script/cucumber +10 -0
- data/sample_app/script/rails +6 -0
- data/sample_app/spec/models/item_spec.rb +5 -0
- data/sample_app/spec/models/user_spec.rb +5 -0
- data/sample_app/spec/spec_helper.rb +27 -0
- data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/sample_app/vendor/plugins/.gitkeep +0 -0
- data/spec/config/shards.yml +217 -0
- data/spec/migrations/10_create_users_using_replication.rb +9 -0
- data/spec/migrations/11_add_field_in_all_slaves.rb +11 -0
- data/spec/migrations/12_create_users_using_block.rb +23 -0
- data/spec/migrations/13_create_users_using_block_and_using.rb +15 -0
- data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +11 -0
- data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +9 -0
- data/spec/migrations/1_create_users_on_master.rb +9 -0
- data/spec/migrations/2_create_users_on_canada.rb +11 -0
- data/spec/migrations/3_create_users_on_both_shards.rb +11 -0
- data/spec/migrations/4_create_users_on_shards_of_a_group.rb +11 -0
- data/spec/migrations/5_create_users_on_multiples_groups.rb +11 -0
- data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +11 -0
- data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +11 -0
- data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +11 -0
- data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +11 -0
- data/spec/octopus/association_shard_tracking_spec.rb +714 -0
- data/spec/octopus/collection_proxy_spec.rb +16 -0
- data/spec/octopus/log_subscriber_spec.rb +19 -0
- data/spec/octopus/migration_spec.rb +115 -0
- data/spec/octopus/model_spec.rb +693 -0
- data/spec/octopus/octopus_spec.rb +123 -0
- data/spec/octopus/proxy_spec.rb +307 -0
- data/spec/octopus/relation_proxy_spec.rb +93 -0
- data/spec/octopus/replicated_slave_grouped_spec.rb +91 -0
- data/spec/octopus/replication_spec.rb +137 -0
- data/spec/octopus/scope_proxy_spec.rb +63 -0
- data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +55 -0
- data/spec/octopus/sharded_spec.rb +33 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +15 -0
- data/spec/support/database_connection.rb +4 -0
- data/spec/support/database_models.rb +118 -0
- data/spec/support/octopus_helper.rb +55 -0
- data/spec/support/query_count.rb +17 -0
- data/spec/support/shared_contexts.rb +18 -0
- data/spec/tasks/octopus.rake_spec.rb +32 -0
- metadata +388 -0
@@ -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,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,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,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
|
@@ -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
|
@@ -0,0 +1,57 @@
|
|
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 'cucumber/rails'
|
8
|
+
|
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
|
13
|
+
|
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!
|
28
|
+
#
|
29
|
+
ActionController::Base.allow_rescue = false
|
30
|
+
|
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:
|
41
|
+
#
|
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
|
52
|
+
#
|
53
|
+
|
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
|