andyjeffries-rubyrep 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +83 -0
- data/License.txt +20 -0
- data/Manifest.txt +151 -0
- data/README.txt +37 -0
- data/bin/rubyrep +8 -0
- data/lib/rubyrep.rb +72 -0
- data/lib/rubyrep/base_runner.rb +195 -0
- data/lib/rubyrep/command_runner.rb +144 -0
- data/lib/rubyrep/committers/buffered_committer.rb +151 -0
- data/lib/rubyrep/committers/committers.rb +152 -0
- data/lib/rubyrep/configuration.rb +275 -0
- data/lib/rubyrep/connection_extenders/connection_extenders.rb +165 -0
- data/lib/rubyrep/connection_extenders/jdbc_extender.rb +65 -0
- data/lib/rubyrep/connection_extenders/mysql_extender.rb +59 -0
- data/lib/rubyrep/connection_extenders/postgresql_extender.rb +277 -0
- data/lib/rubyrep/database_proxy.rb +52 -0
- data/lib/rubyrep/direct_table_scan.rb +75 -0
- data/lib/rubyrep/generate_runner.rb +105 -0
- data/lib/rubyrep/initializer.rb +39 -0
- data/lib/rubyrep/log_helper.rb +30 -0
- data/lib/rubyrep/logged_change.rb +160 -0
- data/lib/rubyrep/logged_change_loader.rb +197 -0
- data/lib/rubyrep/noisy_connection.rb +80 -0
- data/lib/rubyrep/proxied_table_scan.rb +171 -0
- data/lib/rubyrep/proxy_block_cursor.rb +145 -0
- data/lib/rubyrep/proxy_connection.rb +431 -0
- data/lib/rubyrep/proxy_cursor.rb +44 -0
- data/lib/rubyrep/proxy_row_cursor.rb +43 -0
- data/lib/rubyrep/proxy_runner.rb +89 -0
- data/lib/rubyrep/replication_difference.rb +100 -0
- data/lib/rubyrep/replication_extenders/mysql_replication.rb +271 -0
- data/lib/rubyrep/replication_extenders/postgresql_replication.rb +236 -0
- data/lib/rubyrep/replication_extenders/replication_extenders.rb +26 -0
- data/lib/rubyrep/replication_helper.rb +142 -0
- data/lib/rubyrep/replication_initializer.rb +327 -0
- data/lib/rubyrep/replication_run.rb +142 -0
- data/lib/rubyrep/replication_runner.rb +166 -0
- data/lib/rubyrep/replicators/replicators.rb +42 -0
- data/lib/rubyrep/replicators/two_way_replicator.rb +361 -0
- data/lib/rubyrep/scan_progress_printers/progress_bar.rb +65 -0
- data/lib/rubyrep/scan_progress_printers/scan_progress_printers.rb +65 -0
- data/lib/rubyrep/scan_report_printers/scan_detail_reporter.rb +111 -0
- data/lib/rubyrep/scan_report_printers/scan_report_printers.rb +67 -0
- data/lib/rubyrep/scan_report_printers/scan_summary_reporter.rb +75 -0
- data/lib/rubyrep/scan_runner.rb +25 -0
- data/lib/rubyrep/session.rb +230 -0
- data/lib/rubyrep/sync_helper.rb +121 -0
- data/lib/rubyrep/sync_runner.rb +31 -0
- data/lib/rubyrep/syncers/syncers.rb +112 -0
- data/lib/rubyrep/syncers/two_way_syncer.rb +174 -0
- data/lib/rubyrep/table_scan.rb +54 -0
- data/lib/rubyrep/table_scan_helper.rb +46 -0
- data/lib/rubyrep/table_sorter.rb +70 -0
- data/lib/rubyrep/table_spec_resolver.rb +142 -0
- data/lib/rubyrep/table_sync.rb +90 -0
- data/lib/rubyrep/task_sweeper.rb +77 -0
- data/lib/rubyrep/trigger_mode_switcher.rb +63 -0
- data/lib/rubyrep/type_casting_cursor.rb +31 -0
- data/lib/rubyrep/uninstall_runner.rb +93 -0
- data/lib/rubyrep/version.rb +9 -0
- data/rubyrep +8 -0
- data/rubyrep.bat +4 -0
- data/setup.rb +1585 -0
- data/spec/base_runner_spec.rb +218 -0
- data/spec/buffered_committer_spec.rb +274 -0
- data/spec/command_runner_spec.rb +145 -0
- data/spec/committers_spec.rb +178 -0
- data/spec/configuration_spec.rb +203 -0
- data/spec/connection_extender_interface_spec.rb +141 -0
- data/spec/connection_extenders_registration_spec.rb +164 -0
- data/spec/database_proxy_spec.rb +48 -0
- data/spec/database_rake_spec.rb +40 -0
- data/spec/db_specific_connection_extenders_spec.rb +34 -0
- data/spec/db_specific_replication_extenders_spec.rb +38 -0
- data/spec/direct_table_scan_spec.rb +61 -0
- data/spec/dolphins.jpg +0 -0
- data/spec/generate_runner_spec.rb +84 -0
- data/spec/initializer_spec.rb +46 -0
- data/spec/log_helper_spec.rb +39 -0
- data/spec/logged_change_loader_spec.rb +68 -0
- data/spec/logged_change_spec.rb +470 -0
- data/spec/noisy_connection_spec.rb +78 -0
- data/spec/postgresql_replication_spec.rb +48 -0
- data/spec/postgresql_schema_support_spec.rb +212 -0
- data/spec/postgresql_support_spec.rb +63 -0
- data/spec/progress_bar_spec.rb +77 -0
- data/spec/proxied_table_scan_spec.rb +151 -0
- data/spec/proxy_block_cursor_spec.rb +197 -0
- data/spec/proxy_connection_spec.rb +423 -0
- data/spec/proxy_cursor_spec.rb +56 -0
- data/spec/proxy_row_cursor_spec.rb +66 -0
- data/spec/proxy_runner_spec.rb +70 -0
- data/spec/replication_difference_spec.rb +161 -0
- data/spec/replication_extender_interface_spec.rb +367 -0
- data/spec/replication_extenders_spec.rb +32 -0
- data/spec/replication_helper_spec.rb +178 -0
- data/spec/replication_initializer_spec.rb +509 -0
- data/spec/replication_run_spec.rb +443 -0
- data/spec/replication_runner_spec.rb +254 -0
- data/spec/replicators_spec.rb +36 -0
- data/spec/rubyrep_spec.rb +8 -0
- data/spec/scan_detail_reporter_spec.rb +119 -0
- data/spec/scan_progress_printers_spec.rb +68 -0
- data/spec/scan_report_printers_spec.rb +67 -0
- data/spec/scan_runner_spec.rb +50 -0
- data/spec/scan_summary_reporter_spec.rb +61 -0
- data/spec/session_spec.rb +253 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +305 -0
- data/spec/strange_name_support_spec.rb +135 -0
- data/spec/sync_helper_spec.rb +169 -0
- data/spec/sync_runner_spec.rb +78 -0
- data/spec/syncers_spec.rb +171 -0
- data/spec/table_scan_helper_spec.rb +36 -0
- data/spec/table_scan_spec.rb +49 -0
- data/spec/table_sorter_spec.rb +30 -0
- data/spec/table_spec_resolver_spec.rb +111 -0
- data/spec/table_sync_spec.rb +140 -0
- data/spec/task_sweeper_spec.rb +47 -0
- data/spec/trigger_mode_switcher_spec.rb +83 -0
- data/spec/two_way_replicator_spec.rb +721 -0
- data/spec/two_way_syncer_spec.rb +256 -0
- data/spec/type_casting_cursor_spec.rb +50 -0
- data/spec/uninstall_runner_spec.rb +93 -0
- metadata +190 -0
@@ -0,0 +1,145 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
include RR
|
4
|
+
|
5
|
+
describe CommandRunner do
|
6
|
+
before(:each) do
|
7
|
+
@org_commands = CommandRunner.commands
|
8
|
+
CommandRunner.instance_variable_set :@commands, nil
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
CommandRunner.instance_variable_set :@commands, @org_commands
|
13
|
+
end
|
14
|
+
|
15
|
+
it "show_version should print the version string" do
|
16
|
+
$stdout.should_receive(:puts).with(/rubyrep version ([0-9]+\.){2}[0-9]+/)
|
17
|
+
CommandRunner.show_version
|
18
|
+
end
|
19
|
+
|
20
|
+
it "register should register commands, commands should return it" do
|
21
|
+
CommandRunner.register :bla => :bla_command
|
22
|
+
CommandRunner.register :blub => :blub_command
|
23
|
+
CommandRunner.commands.should == {
|
24
|
+
:bla => :bla_command,
|
25
|
+
:blub => :blub_command
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "run should print a short help if --help is specified" do
|
30
|
+
org_stderr = $stderr
|
31
|
+
$stderr = StringIO.new
|
32
|
+
begin
|
33
|
+
CommandRunner.register 'c1' => {:description => 'desc 1'}, 'c2' => {:description => 'desc 2'}
|
34
|
+
CommandRunner.run(['--help'])
|
35
|
+
$stderr.string.should =~ /Usage/
|
36
|
+
$stderr.string.should =~ /c1.*desc 1\n/
|
37
|
+
$stderr.string.should =~ /c2.*desc 2\n/
|
38
|
+
ensure
|
39
|
+
$stderr = org_stderr
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "run should print help if no command line parameters are given" do
|
44
|
+
org_stderr = $stderr
|
45
|
+
$stderr = StringIO.new
|
46
|
+
begin
|
47
|
+
CommandRunner.run([]).should == 1
|
48
|
+
$stderr.string.should =~ /Available commands/
|
49
|
+
ensure
|
50
|
+
$stderr = org_stderr
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "run should print help if --help or help without further params is given" do
|
55
|
+
org_stderr = $stderr
|
56
|
+
$stderr = StringIO.new
|
57
|
+
begin
|
58
|
+
CommandRunner.run(['--help']).should == 0
|
59
|
+
$stderr.string.should =~ /Available commands/
|
60
|
+
$stderr = StringIO.new
|
61
|
+
CommandRunner.run(['help']).should == 0
|
62
|
+
$stderr.string.should =~ /Available commands/
|
63
|
+
ensure
|
64
|
+
$stderr = org_stderr
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "run should print version if --version is given" do
|
69
|
+
CommandRunner.should_receive(:show_version)
|
70
|
+
CommandRunner.run(['--version'])
|
71
|
+
end
|
72
|
+
|
73
|
+
it "run should call the specified command with the specified params" do
|
74
|
+
c = mock('dummy_command')
|
75
|
+
c.should_receive(:run).with(['param1', 'param2'])
|
76
|
+
CommandRunner.register 'dummy_command' => {:command => c}
|
77
|
+
CommandRunner.run(['dummy_command', 'param1', 'param2'])
|
78
|
+
end
|
79
|
+
|
80
|
+
it "run should print help if unknown command is given" do
|
81
|
+
org_stderr = $stderr
|
82
|
+
$stderr = StringIO.new
|
83
|
+
begin
|
84
|
+
CommandRunner.run('non-existing-command').should == 1
|
85
|
+
$stderr.string.should =~ /Available commands/
|
86
|
+
ensure
|
87
|
+
$stderr = org_stderr
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "run should print stacktrace if --verbose option is given" do
|
92
|
+
org_stderr = $stderr
|
93
|
+
$stderr = StringIO.new
|
94
|
+
begin
|
95
|
+
c = mock('dummy_command')
|
96
|
+
c.stub!(:run).and_return {raise 'bla'}
|
97
|
+
CommandRunner.register 'dummy_command' => {:command => c}
|
98
|
+
CommandRunner.run(['--verbose', 'dummy_command', '-c', 'non_existing_file']).should == 1
|
99
|
+
$stderr.string.should =~ /Exception caught/
|
100
|
+
$stderr.string.should =~ /command_runner.rb:[0-9]+:in /
|
101
|
+
|
102
|
+
# also verify that no stacktrace is printed if --verbose is not specified
|
103
|
+
$stderr = StringIO.new
|
104
|
+
CommandRunner.run(['dummy_command', '-c', 'non_existing_file']).should == 1
|
105
|
+
$stderr.string.should =~ /Exception caught/
|
106
|
+
$stderr.string.should_not =~ /command_runner.rb:[0-9]+:in /
|
107
|
+
ensure
|
108
|
+
$stderr = org_stderr
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "rubyrep should call CommandRunner#run" do
|
113
|
+
CommandRunner.should_receive(:run).with(ARGV).and_return(0)
|
114
|
+
Kernel.any_instance_should_receive(:exit) {
|
115
|
+
load File.dirname(__FILE__) + '/../bin/rubyrep'
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe HelpRunner do
|
121
|
+
it "should register itself" do
|
122
|
+
CommandRunner.commands['help'][:command].should == HelpRunner
|
123
|
+
CommandRunner.commands['help'][:description].should be_an_instance_of(String)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "run should call help for the specified command" do
|
127
|
+
CommandRunner.should_receive(:run).with(['dummy_command', '--help'])
|
128
|
+
HelpRunner.run(['dummy_command'])
|
129
|
+
end
|
130
|
+
|
131
|
+
it "run should print help for itself if '--help' or 'help' is specified" do
|
132
|
+
org_stderr = $stderr
|
133
|
+
$stderr = StringIO.new
|
134
|
+
begin
|
135
|
+
HelpRunner.run(['--help'])
|
136
|
+
$stderr.string.should =~ /Shows the help for the specified command/
|
137
|
+
|
138
|
+
$stderr = StringIO.new
|
139
|
+
HelpRunner.run(['help'])
|
140
|
+
$stderr.string.should =~ /Shows the help for the specified command/
|
141
|
+
ensure
|
142
|
+
$stderr = org_stderr
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
include RR
|
4
|
+
|
5
|
+
describe Committers do
|
6
|
+
before(:each) do
|
7
|
+
@old_committers = Committers.committers
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
Committers.instance_variable_set :@committers, @old_committers
|
12
|
+
end
|
13
|
+
|
14
|
+
it "committers should return empty hash if nil" do
|
15
|
+
Committers.instance_variable_set :@committers, nil
|
16
|
+
Committers.committers.should == {}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "committers should return the registered committers" do
|
20
|
+
Committers.instance_variable_set :@committers, :dummy_data
|
21
|
+
Committers.committers.should == :dummy_data
|
22
|
+
end
|
23
|
+
|
24
|
+
it "register should register the provided commiter" do
|
25
|
+
Committers.instance_variable_set :@committers, nil
|
26
|
+
Committers.register :a_key => :a
|
27
|
+
Committers.register :b_key => :b
|
28
|
+
Committers.committers[:a_key].should == :a
|
29
|
+
Committers.committers[:b_key].should == :b
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
describe "Committer", :shared => true do
|
35
|
+
it "should support the right constructor interface" do
|
36
|
+
session = mock("session")
|
37
|
+
session.should_receive(:left).any_number_of_times \
|
38
|
+
.and_return(mock("left connection", :null_object => true))
|
39
|
+
session.should_receive(:right).any_number_of_times \
|
40
|
+
.and_return(mock("right connection", :null_object => true))
|
41
|
+
@committer.class.new session
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should proxy insert_record, update_record and delete_record calls" do
|
45
|
+
left_connection = mock("left connection", :null_object => true)
|
46
|
+
left_connection.should_receive(:insert_record).with("left", :dummy_insert_values)
|
47
|
+
|
48
|
+
right_connection = mock("right connection", :null_object => true)
|
49
|
+
right_connection.should_receive(:update_record).with("right", :dummy_update_values, :dummy_org_key)
|
50
|
+
right_connection.should_receive(:delete_record).with("right", :dummy_delete_values)
|
51
|
+
|
52
|
+
session = mock("session")
|
53
|
+
session.should_receive(:left).any_number_of_times.and_return(left_connection)
|
54
|
+
session.should_receive(:right).any_number_of_times.and_return(right_connection)
|
55
|
+
|
56
|
+
committer = @committer.class.new session
|
57
|
+
|
58
|
+
committer.insert_record :left, 'left', :dummy_insert_values
|
59
|
+
committer.update_record :right, 'right', :dummy_update_values, :dummy_org_key
|
60
|
+
committer.delete_record :right, 'right', :dummy_delete_values
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should support finalize" do
|
64
|
+
@committer.finalize(false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe Committers::DefaultCommitter do
|
69
|
+
before(:each) do
|
70
|
+
@session = mock("session")
|
71
|
+
@session.should_receive(:left).any_number_of_times.and_return(:left_connection)
|
72
|
+
@session.should_receive(:right).any_number_of_times.and_return(:right_connection)
|
73
|
+
@committer = Committers::DefaultCommitter.new @session
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should register itself" do
|
77
|
+
Committers.committers[:default].should == Committers::DefaultCommitter
|
78
|
+
end
|
79
|
+
|
80
|
+
it "initialize should store the provided parameters" do
|
81
|
+
@committer.session.should == @session
|
82
|
+
@committer.connections \
|
83
|
+
.should == {:left => @session.left, :right => @session.right}
|
84
|
+
end
|
85
|
+
|
86
|
+
it "new_transaction? should return false" do
|
87
|
+
@committer.new_transaction?.should be_false
|
88
|
+
end
|
89
|
+
|
90
|
+
it_should_behave_like "Committer"
|
91
|
+
end
|
92
|
+
|
93
|
+
describe Committers::NeverCommitter do
|
94
|
+
before(:each) do
|
95
|
+
@old_session = Committers::NeverCommitter.current_session
|
96
|
+
Committers::NeverCommitter.current_session = nil
|
97
|
+
@session = mock("session")
|
98
|
+
@session.should_receive(:left).any_number_of_times \
|
99
|
+
.and_return(mock("left connection", :null_object => true))
|
100
|
+
@session.should_receive(:right).any_number_of_times \
|
101
|
+
.and_return(mock("right connection", :null_object => true))
|
102
|
+
@committer = Committers::NeverCommitter.new @session
|
103
|
+
end
|
104
|
+
|
105
|
+
after(:each) do
|
106
|
+
Committers::NeverCommitter.current_session = @old_session
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should register itself" do
|
110
|
+
Committers.committers[:never_commit].should == Committers::NeverCommitter
|
111
|
+
end
|
112
|
+
|
113
|
+
it "initialize should store the provided parameters" do
|
114
|
+
@committer.session.should == @session
|
115
|
+
@committer.connections \
|
116
|
+
.should == {:left => @session.left, :right => @session.right}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "initialize should rollback the previous current session and then register the new one as current session" do
|
120
|
+
old_session = mock("old session", :null_object => true)
|
121
|
+
new_session = mock("new session", :null_object => true)
|
122
|
+
Committers::NeverCommitter.current_session = old_session
|
123
|
+
Committers::NeverCommitter.should_receive(:rollback_current_session)
|
124
|
+
|
125
|
+
Committers::NeverCommitter.new new_session
|
126
|
+
Committers::NeverCommitter.current_session.should == new_session
|
127
|
+
end
|
128
|
+
|
129
|
+
it "initialize should start new transactions" do
|
130
|
+
# Ensure that initialize handles the case of no previous database session
|
131
|
+
# being present
|
132
|
+
Committers::NeverCommitter.current_session = nil
|
133
|
+
new_session = mock("new session")
|
134
|
+
|
135
|
+
left_connection = mock("left connection")
|
136
|
+
left_connection.should_receive :begin_db_transaction
|
137
|
+
new_session.should_receive(:left).any_number_of_times.and_return(left_connection)
|
138
|
+
|
139
|
+
right_connection = mock("right connection")
|
140
|
+
right_connection.should_receive :begin_db_transaction
|
141
|
+
new_session.should_receive(:right).any_number_of_times.and_return(right_connection)
|
142
|
+
|
143
|
+
@committer = Committers::NeverCommitter.new new_session
|
144
|
+
end
|
145
|
+
|
146
|
+
it "rollback_current_session should rollback current session" do
|
147
|
+
old_session = mock("old session")
|
148
|
+
|
149
|
+
left_connection = mock("left connection")
|
150
|
+
left_connection.should_receive :rollback_db_transaction
|
151
|
+
old_session.should_receive(:left).and_return(left_connection)
|
152
|
+
|
153
|
+
right_connection = mock("right connection")
|
154
|
+
right_connection.should_receive :rollback_db_transaction
|
155
|
+
old_session.should_receive(:right).and_return(right_connection)
|
156
|
+
|
157
|
+
Committers::NeverCommitter.current_session = old_session
|
158
|
+
Committers::NeverCommitter.rollback_current_session
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should work will real sessions" do
|
162
|
+
session = Session.new(standard_config)
|
163
|
+
Committers::NeverCommitter.new session
|
164
|
+
Committers::NeverCommitter.new session
|
165
|
+
Committers::NeverCommitter.rollback_current_session
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should work will real proxied sessions" do
|
169
|
+
ensure_proxy
|
170
|
+
session = Session.new(proxied_config)
|
171
|
+
Committers::NeverCommitter.new session
|
172
|
+
Committers::NeverCommitter.new session
|
173
|
+
Committers::NeverCommitter.rollback_current_session
|
174
|
+
end
|
175
|
+
|
176
|
+
it_should_behave_like "Committer"
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
include RR
|
4
|
+
|
5
|
+
describe Configuration do
|
6
|
+
before(:each) do
|
7
|
+
end
|
8
|
+
|
9
|
+
it "initialize should set #left and #right to empty hashes" do
|
10
|
+
config = Configuration.new
|
11
|
+
config.left.should == {}
|
12
|
+
config.right.should == {}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "initialize should set #options to the default options" do
|
16
|
+
config = Configuration.new
|
17
|
+
config.options.should == Configuration::DEFAULT_OPTIONS
|
18
|
+
end
|
19
|
+
|
20
|
+
it "options= should merge the provided into the existing options" do
|
21
|
+
config = Configuration.new
|
22
|
+
config.options = {:bla => :bla}
|
23
|
+
config.options = {:bla => :blub}
|
24
|
+
config.options[:bla].should == :blub
|
25
|
+
end
|
26
|
+
|
27
|
+
it "each_matching_option should yield if general option matches" do
|
28
|
+
config = Configuration.new
|
29
|
+
config.options = {:bla => :blub}
|
30
|
+
yielded = []
|
31
|
+
config.each_matching_option(:bla) {|spec, value| yielded << [spec, value]}
|
32
|
+
yielded.should == [[nil, :blub]]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "each_matching_option should yield if table specific options match" do
|
36
|
+
config = Configuration.new
|
37
|
+
config.options = {:a => 1}
|
38
|
+
config.add_table_options 't1', :a => 2
|
39
|
+
config.add_table_options 't2', :b => 3
|
40
|
+
config.add_table_options 't3', :a => 4
|
41
|
+
yielded = []
|
42
|
+
config.each_matching_option(:a) {|spec, value| yielded << [spec, value]}
|
43
|
+
yielded.should == [
|
44
|
+
[nil, 1],
|
45
|
+
['t1', 2],
|
46
|
+
['t3', 4]
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "each_matching_option should not yield unmatching options" do
|
51
|
+
config = Configuration.new
|
52
|
+
config.options = {:a => :blub}
|
53
|
+
config.add_table_options 'dummy_table', :b => :blub
|
54
|
+
yielded = []
|
55
|
+
config.each_matching_option(:c) {|spec, value| yielded << [spec, value]}
|
56
|
+
yielded.should == []
|
57
|
+
end
|
58
|
+
|
59
|
+
it "options_for_table should return the general options if there are no table specific options at all" do
|
60
|
+
config = Configuration.new
|
61
|
+
config.options_for_table('b').should == \
|
62
|
+
Syncers::TwoWaySyncer.default_options.clone.
|
63
|
+
merge(Replicators::TwoWayReplicator.default_options.clone).
|
64
|
+
merge(config.options)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "included_table_specs should return the list of included table specifications" do
|
68
|
+
config = Configuration.new
|
69
|
+
config.include_tables('a', {:bla => :blub})
|
70
|
+
config.include_tables('a, b')
|
71
|
+
config.include_tables(/a/)
|
72
|
+
config.included_table_specs.should == ['a', 'a, b', /a/]
|
73
|
+
end
|
74
|
+
|
75
|
+
it "included_table_specs should save the options if provided" do
|
76
|
+
config = Configuration.new
|
77
|
+
config.include_tables('a', {:bla => :blub})
|
78
|
+
config.options_for_table('a')[:bla].should == :blub
|
79
|
+
end
|
80
|
+
|
81
|
+
it "include_tables should include the specified table specs" do
|
82
|
+
config = Configuration.new
|
83
|
+
config.include_tables('a')
|
84
|
+
config.include_tables(/b/)
|
85
|
+
config.included_table_specs.include?('a').should be_true
|
86
|
+
config.included_table_specs.include?(/b/).should be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "include_table should alias to include_tables" do
|
90
|
+
config = Configuration.new
|
91
|
+
config.include_table('a')
|
92
|
+
config.included_table_specs.include?('a').should be_true
|
93
|
+
end
|
94
|
+
|
95
|
+
it "exclude_tables should exclude the specified table specs" do
|
96
|
+
config = Configuration.new
|
97
|
+
config.exclude_tables('a')
|
98
|
+
config.exclude_tables(/b/)
|
99
|
+
config.excluded_table_specs.include?('a').should be_true
|
100
|
+
config.excluded_table_specs.include?(/b/).should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "exclude_table should alias to exclude_tables" do
|
104
|
+
config = Configuration.new
|
105
|
+
config.exclude_table('a')
|
106
|
+
config.excluded_table_specs.include?('a').should be_true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "exclude_rubyrep_tables should exclude the rubyrep infrastructure tables" do
|
110
|
+
config = Configuration.new
|
111
|
+
config.exclude_rubyrep_tables
|
112
|
+
config.excluded_table_specs.include?(/^rr_.*/).should be_true
|
113
|
+
end
|
114
|
+
|
115
|
+
it "excluded_table_specs should return the list of excluded table specifications" do
|
116
|
+
config = Configuration.new
|
117
|
+
config.exclude_tables('a')
|
118
|
+
config.exclude_tables('a, b')
|
119
|
+
config.exclude_tables(/a/)
|
120
|
+
config.excluded_table_specs.should == ['a', 'a, b', /a/]
|
121
|
+
end
|
122
|
+
|
123
|
+
it "options_for_table should return the general options if there are no matching table specific options" do
|
124
|
+
config = Configuration.new
|
125
|
+
config.include_tables(/a/, {:bla => :blub})
|
126
|
+
config.options_for_table('b').should == \
|
127
|
+
Syncers::TwoWaySyncer.default_options.clone.
|
128
|
+
merge(Replicators::TwoWayReplicator.default_options.clone).
|
129
|
+
merge(config.options)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "options_for_table should return table specific options mixed in with default options" do
|
133
|
+
config = Configuration.new
|
134
|
+
config.include_tables(/a/, {:bla => :blub})
|
135
|
+
config.options_for_table('a').should == \
|
136
|
+
Syncers::TwoWaySyncer.default_options.clone.
|
137
|
+
merge(Replicators::TwoWayReplicator.default_options.clone).
|
138
|
+
merge(config.options).
|
139
|
+
merge(:bla => :blub)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "options_for_table should return last added version of added options for matching table spec" do
|
143
|
+
config = Configuration.new
|
144
|
+
config.include_tables(/a/, {:bla => :blub})
|
145
|
+
config.include_tables('a', {:bla => :blok})
|
146
|
+
config.include_tables(/x/, {:bla => :bar})
|
147
|
+
config.include_tables('y', {:bla => :foo})
|
148
|
+
config.options_for_table('a').should == \
|
149
|
+
Syncers::TwoWaySyncer.default_options.clone.
|
150
|
+
merge(Replicators::TwoWayReplicator.default_options.clone).
|
151
|
+
merge(config.options).
|
152
|
+
merge(:bla => :blok)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "options_for_table should match against table pair specs" do
|
156
|
+
config = Configuration.new
|
157
|
+
config.add_table_options('a, b', {:bla => :blub})
|
158
|
+
config.options_for_table('a')[:bla].should == :blub
|
159
|
+
end
|
160
|
+
|
161
|
+
it "options_for_table should match against regular expression specs" do
|
162
|
+
config = Configuration.new
|
163
|
+
config.add_table_options(/a/, {:bla => :blub})
|
164
|
+
config.options_for_table('a')[:bla].should == :blub
|
165
|
+
end
|
166
|
+
|
167
|
+
it "options_for_table should match against pure table name specs" do
|
168
|
+
config = Configuration.new
|
169
|
+
config.add_table_options('a', {:bla => :blub})
|
170
|
+
config.options_for_table('a')[:bla].should == :blub
|
171
|
+
end
|
172
|
+
|
173
|
+
it "add_table_options should not create table_spec duplicates" do
|
174
|
+
config = Configuration.new
|
175
|
+
config.add_table_options(/a/, {:bla => :blub})
|
176
|
+
config.add_table_options(/a/, {:foo => :bar})
|
177
|
+
config.options_for_table('a').should == \
|
178
|
+
Syncers::TwoWaySyncer.default_options.clone.
|
179
|
+
merge(Replicators::TwoWayReplicator.default_options.clone).
|
180
|
+
merge(config.options).
|
181
|
+
merge(:bla => :blub, :foo => :bar)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "add_table_option should alias to add_table_options" do
|
185
|
+
config = Configuration.new
|
186
|
+
config.add_table_option(/a/, {:bla => :blub})
|
187
|
+
config.options_for_table('a')[:bla].should == :blub
|
188
|
+
end
|
189
|
+
|
190
|
+
it "add_table_options should include default syncer options" do
|
191
|
+
config = Configuration.new
|
192
|
+
config.options = {:syncer => :one_way}
|
193
|
+
|
194
|
+
# overwrite one syncer option
|
195
|
+
config.add_table_options(/a/, {:delete => true})
|
196
|
+
|
197
|
+
options = config.options_for_table('a')
|
198
|
+
Syncers::OneWaySyncer.default_options.each do |key, value|
|
199
|
+
options[key].should == value unless key == :delete
|
200
|
+
end
|
201
|
+
options[:delete].should == true
|
202
|
+
end
|
203
|
+
end
|