database_cleaner 1.5.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile.lock +4 -4
  3. data/History.rdoc +44 -0
  4. data/README.markdown +29 -6
  5. data/VERSION.yml +2 -2
  6. data/lib/database_cleaner/active_record/base.rb +17 -1
  7. data/lib/database_cleaner/active_record/deletion.rb +23 -2
  8. data/lib/database_cleaner/active_record/truncation.rb +2 -2
  9. data/lib/database_cleaner/base.rb +2 -0
  10. data/lib/database_cleaner/mongoid/truncation.rb +1 -1
  11. data/lib/database_cleaner/null_strategy.rb +5 -0
  12. data/lib/database_cleaner/redis/base.rb +1 -1
  13. data/lib/database_cleaner/safeguard.rb +72 -0
  14. data/lib/database_cleaner.rb +6 -2
  15. metadata +6 -91
  16. data/examples/Gemfile +0 -1
  17. data/examples/Gemfile.lock +0 -286
  18. data/examples/config/database.yml +0 -7
  19. data/examples/config/database.yml.example +0 -8
  20. data/examples/config/redis.yml +0 -8
  21. data/examples/db/activerecord_one.db +0 -0
  22. data/examples/db/activerecord_two.db +0 -0
  23. data/examples/db/datamapper_default.db +0 -0
  24. data/examples/db/datamapper_one.db +0 -0
  25. data/examples/db/datamapper_two.db +0 -0
  26. data/examples/db/sqlite_databases_go_here +0 -0
  27. data/examples/features/example.feature +0 -11
  28. data/examples/features/example_multiple_db.feature +0 -23
  29. data/examples/features/example_multiple_orm.feature +0 -22
  30. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  31. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  32. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  33. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  34. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  35. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  36. data/examples/features/step_definitions/translation_steps.rb +0 -55
  37. data/examples/features/support/env.rb +0 -61
  38. data/examples/lib/activerecord_models.rb +0 -41
  39. data/examples/lib/couchpotato_models.rb +0 -61
  40. data/examples/lib/datamapper_models.rb +0 -50
  41. data/examples/lib/mongoid_models.rb +0 -44
  42. data/examples/lib/mongomapper_models.rb +0 -51
  43. data/examples/lib/neo4j_models.rb +0 -17
  44. data/examples/lib/ohm_models.rb +0 -43
  45. data/examples/lib/redis_models.rb +0 -65
  46. data/examples/lib/sequel_models.rb +0 -9
  47. data/features/cleaning.feature +0 -30
  48. data/features/cleaning_default_strategy.feature +0 -23
  49. data/features/cleaning_multiple_dbs.feature +0 -22
  50. data/features/cleaning_multiple_orms.feature +0 -67
  51. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  52. data/features/step_definitions/ohm_steps.rb +0 -31
  53. data/features/step_definitions/redis_steps.rb +0 -31
  54. data/features/support/env.rb +0 -4
  55. data/features/support/feature_runner.rb +0 -39
  56. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  57. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  58. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  59. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  60. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  61. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  62. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  63. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  64. data/spec/database_cleaner/base_spec.rb +0 -617
  65. data/spec/database_cleaner/configuration_spec.rb +0 -345
  66. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  67. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  68. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  69. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  70. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  71. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  72. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  73. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  74. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  75. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  76. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  77. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  78. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  79. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  80. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  81. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  82. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  83. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  84. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  85. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  86. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  87. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  88. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  89. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  90. data/spec/database_cleaner/shared_strategy.rb +0 -15
  91. data/spec/rcov.opts +0 -1
  92. data/spec/spec_helper.rb +0 -21
  93. data/spec/support/active_record/database_setup.rb +0 -6
  94. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  95. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  96. data/spec/support/active_record/mysql2_setup.rb +0 -39
  97. data/spec/support/active_record/mysql_setup.rb +0 -38
  98. data/spec/support/active_record/postgresql_setup.rb +0 -48
  99. data/spec/support/active_record/schema_setup.rb +0 -17
  100. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  101. data/spec/support/data_mapper/schema_setup.rb +0 -15
  102. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
@@ -1,180 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'active_record'
3
- require 'active_record/connection_adapters/mysql_adapter'
4
- require 'active_record/connection_adapters/mysql2_adapter'
5
- require 'active_record/connection_adapters/sqlite3_adapter'
6
- require 'active_record/connection_adapters/postgresql_adapter'
7
-
8
- require 'database_cleaner/active_record/truncation'
9
-
10
- module ActiveRecord
11
- module ConnectionAdapters
12
- #JdbcAdapter IBM_DBAdapter
13
- [ MysqlAdapter, Mysql2Adapter, SQLite3Adapter, PostgreSQLAdapter ].each do |adapter|
14
- describe adapter, "#truncate_table" do
15
- it "responds" do
16
- adapter.instance_methods.should include(:truncate_table)
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
23
- module DatabaseCleaner
24
- module ActiveRecord
25
-
26
- describe Truncation do
27
- let(:connection) { double('connection') }
28
-
29
- before(:each) do
30
- connection.stub(:disable_referential_integrity).and_yield
31
- connection.stub(:database_cleaner_view_cache).and_return([])
32
- ::ActiveRecord::Base.stub(:connection).and_return(connection)
33
- end
34
-
35
- describe '#clean' do
36
- it "should truncate all tables except for schema_migrations" do
37
- connection.stub(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
38
-
39
- connection.should_receive(:truncate_tables).with(['widgets', 'dogs'])
40
- Truncation.new.clean
41
- end
42
-
43
- it "should use ActiveRecord's schema_migrations_table_name" do
44
- connection.stub(:database_cleaner_table_cache).and_return(%w[pre_schema_migrations_suf widgets dogs])
45
- ::ActiveRecord::Base.stub(:table_name_prefix).and_return('pre_')
46
- ::ActiveRecord::Base.stub(:table_name_suffix).and_return('_suf')
47
-
48
- connection.should_receive(:truncate_tables).with(['widgets', 'dogs'])
49
-
50
- Truncation.new.clean
51
- end
52
-
53
- it "should only truncate the tables specified in the :only option when provided" do
54
- connection.stub(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
55
-
56
- connection.should_receive(:truncate_tables).with(['widgets'])
57
-
58
- Truncation.new(:only => ['widgets']).clean
59
- end
60
-
61
- it "should not truncate the tables specified in the :except option" do
62
- connection.stub(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
63
-
64
- connection.should_receive(:truncate_tables).with(['dogs'])
65
-
66
- Truncation.new(:except => ['widgets']).clean
67
- end
68
-
69
- it "should raise an error when :only and :except options are used" do
70
- running {
71
- Truncation.new(:except => ['widgets'], :only => ['widgets'])
72
- }.should raise_error(ArgumentError)
73
- end
74
-
75
- it "should raise an error when invalid options are provided" do
76
- running { Truncation.new(:foo => 'bar') }.should raise_error(ArgumentError)
77
- end
78
-
79
- it "should not truncate views" do
80
- connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs])
81
- connection.stub(:database_cleaner_view_cache).and_return(["widgets"])
82
-
83
- connection.should_receive(:truncate_tables).with(['dogs'])
84
-
85
- Truncation.new.clean
86
- end
87
-
88
- describe "relying on #pre_count_truncate_tables if connection allows it" do
89
- subject { Truncation.new }
90
-
91
- it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do
92
- connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs])
93
- connection.stub(:database_cleaner_view_cache).and_return(["widgets"])
94
-
95
- subject.instance_variable_set(:"@pre_count", true)
96
-
97
- connection.should_not_receive(:truncate_tables).with(['dogs'])
98
- connection.should_receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
99
-
100
- subject.clean
101
- end
102
-
103
- it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do
104
- connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs])
105
- connection.stub(:database_cleaner_view_cache).and_return(["widgets"])
106
-
107
- subject.instance_variable_set(:"@pre_count", false)
108
-
109
- connection.should_not_receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
110
- connection.should_receive(:truncate_tables).with(['dogs'])
111
-
112
- subject.clean
113
- end
114
- end
115
-
116
- context 'when :cache_tables is set to true' do
117
- it 'caches the list of tables to be truncated' do
118
- connection.should_receive(:database_cleaner_table_cache).and_return([])
119
- connection.should_not_receive(:tables)
120
-
121
- connection.stub(:truncate_tables)
122
- Truncation.new({ :cache_tables => true }).clean
123
- end
124
- end
125
-
126
- context 'when :cache_tables is set to false' do
127
- it 'does not cache the list of tables to be truncated' do
128
- connection.should_not_receive(:database_cleaner_table_cache)
129
- connection.should_receive(:tables).and_return([])
130
-
131
- connection.stub(:truncate_tables)
132
- Truncation.new({ :cache_tables => false }).clean
133
- end
134
- end
135
- end
136
-
137
- describe '#pre_count?' do
138
- before(:each) do
139
- connection.stub(:disable_referential_integrity).and_yield
140
- connection.stub(:database_cleaner_view_cache).and_return([])
141
- ::ActiveRecord::Base.stub(:connection).and_return(connection)
142
- end
143
-
144
- subject { Truncation.new }
145
- its(:pre_count?) { should eq false }
146
-
147
- it 'should return true if @reset_id is set and non false or nil' do
148
- subject.instance_variable_set(:"@pre_count", true)
149
- subject.send(:pre_count?).should eq true
150
- end
151
-
152
- it 'should return false if @reset_id is set to false' do
153
- subject.instance_variable_set(:"@pre_count", false)
154
- subject.send(:pre_count?).should eq false
155
- end
156
- end
157
-
158
- describe '#reset_ids?' do
159
- before(:each) do
160
- connection.stub(:disable_referential_integrity).and_yield
161
- connection.stub(:database_cleaner_view_cache).and_return([])
162
- ::ActiveRecord::Base.stub(:connection).and_return(connection)
163
- end
164
-
165
- subject { Truncation.new }
166
- its(:reset_ids?) { should eq true }
167
-
168
- it 'should return true if @reset_id is set and non false or nil' do
169
- subject.instance_variable_set(:"@reset_ids", 'Something')
170
- subject.send(:reset_ids?).should eq true
171
- end
172
-
173
- it 'should return false if @reset_id is set to false' do
174
- subject.instance_variable_set(:"@reset_ids", false)
175
- subject.send(:reset_ids?).should eq false
176
- end
177
- end
178
- end
179
- end
180
- end