jonrowe-database_cleaner 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/History.txt +85 -0
  2. data/LICENSE +20 -0
  3. data/README.textile +118 -0
  4. data/Rakefile +46 -0
  5. data/TODO +0 -0
  6. data/VERSION.yml +5 -0
  7. data/cucumber.yml +1 -0
  8. data/examples/features/example.feature +11 -0
  9. data/examples/features/step_definitions/example_steps.rb +8 -0
  10. data/examples/features/support/env.rb +23 -0
  11. data/examples/lib/activerecord_models.rb +12 -0
  12. data/examples/lib/couchpotato_models.rb +21 -0
  13. data/examples/lib/datamapper_models.rb +16 -0
  14. data/examples/lib/mongomapper_models.rb +17 -0
  15. data/features/cleaning.feature +20 -0
  16. data/features/step_definitions/database_cleaner_steps.rb +25 -0
  17. data/features/support/env.rb +7 -0
  18. data/lib/database_cleaner.rb +3 -0
  19. data/lib/database_cleaner/active_record/transaction.rb +30 -0
  20. data/lib/database_cleaner/active_record/truncation.rb +110 -0
  21. data/lib/database_cleaner/configuration.rb +127 -0
  22. data/lib/database_cleaner/couch_potato/truncation.rb +26 -0
  23. data/lib/database_cleaner/cucumber.rb +8 -0
  24. data/lib/database_cleaner/data_mapper/transaction.rb +23 -0
  25. data/lib/database_cleaner/data_mapper/truncation.rb +142 -0
  26. data/lib/database_cleaner/mongo_mapper/truncation.rb +30 -0
  27. data/lib/database_cleaner/truncation_base.rb +41 -0
  28. data/spec/database_cleaner/active_record/transaction_spec.rb +165 -0
  29. data/spec/database_cleaner/active_record/truncation_spec.rb +136 -0
  30. data/spec/database_cleaner/configuration_spec.rb +118 -0
  31. data/spec/database_cleaner/couch_potato/truncation_spec.rb +40 -0
  32. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +81 -0
  33. data/spec/spec.opts +6 -0
  34. data/spec/spec_helper.rb +12 -0
  35. metadata +109 -0
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'database_cleaner/couch_potato/truncation'
3
+ require 'couch_potato'
4
+
5
+ module DatabaseCleaner
6
+ module CouchPotato
7
+
8
+ describe Truncation do
9
+ before(:each) do
10
+ @database = mock('database')
11
+ ::CouchPotato.stub!(:couchrest_database).and_return(@database)
12
+ end
13
+
14
+ it "should re-create the database" do
15
+ @database.should_receive(:recreate!)
16
+
17
+ Truncation.new.clean
18
+ end
19
+
20
+ it "should raise an error when the :only option is used" do
21
+ running {
22
+ Truncation.new(:only => ['document-type'])
23
+ }.should raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should raise an error when the :except option is used" do
27
+ running {
28
+ Truncation.new(:except => ['document-type'])
29
+ }.should raise_error(ArgumentError)
30
+ end
31
+
32
+ it "should raise an error when invalid options are provided" do
33
+ running {
34
+ Truncation.new(:foo => 'bar')
35
+ }.should raise_error(ArgumentError)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mongo_mapper'
3
+ require 'database_cleaner/mongo_mapper/truncation'
4
+
5
+ MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
6
+ TEST_DATABASE = 'database_cleaner_specs'
7
+ MongoMapper.database = TEST_DATABASE
8
+
9
+ class Widget
10
+ include MongoMapper::Document
11
+ key :name, String
12
+ end
13
+ class Gadget
14
+ include MongoMapper::Document
15
+ key :name, String
16
+ end
17
+
18
+
19
+ module DatabaseCleaner
20
+ module MongoMapper
21
+
22
+ describe Truncation do
23
+ before(:each) do
24
+ ::MongoMapper.connection.drop_database(TEST_DATABASE)
25
+ #::MongoMapper.connection.db(TEST_DATABASE).collections.each {|c| c.remove }
26
+ #::MongoMapper.database = TEST_DATABASE
27
+ end
28
+
29
+ def ensure_counts(expected_counts)
30
+ # I had to add this sanity_check garbage because I was getting non-determinisc results from mongomapper at times..
31
+ # very odd and disconcerting...
32
+ sanity_check = expected_counts.delete(:sanity_check)
33
+ begin
34
+ expected_counts.each do |model_class, expected_count|
35
+ model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
36
+ end
37
+ rescue Spec::Expectations::ExpectationNotMetError => e
38
+ raise !sanity_check ? e : Spec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
39
+ end
40
+ end
41
+
42
+ def create_widget(attrs={})
43
+ Widget.new({:name => 'some widget'}.merge(attrs)).save!
44
+ end
45
+
46
+ def create_gadget(attrs={})
47
+ Gadget.new({:name => 'some gadget'}.merge(attrs)).save!
48
+ end
49
+
50
+ it "truncates all collections by default" do
51
+ create_widget
52
+ create_gadget
53
+ ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
54
+ Truncation.new.clean
55
+ ensure_counts(Widget => 0, Gadget => 0)
56
+ end
57
+
58
+ context "when collections are provided to the :only option" do
59
+ it "only truncates the specified collections" do
60
+ create_widget
61
+ create_gadget
62
+ ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
63
+ Truncation.new(:only => ['widgets']).clean
64
+ ensure_counts(Widget => 0, Gadget => 1)
65
+ end
66
+ end
67
+
68
+ context "when collections are provided to the :except option" do
69
+ it "truncates all but the specified collections" do
70
+ create_widget
71
+ create_gadget
72
+ ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
73
+ Truncation.new(:except => ['widgets']).clean
74
+ ensure_counts(Widget => 1, Gadget => 0)
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format nested
3
+ --loadby
4
+ mtime
5
+ --reverse
6
+ --backtrace
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'active_record'
4
+ require 'mongo_mapper'
5
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
6
+ require 'database_cleaner'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
11
+
12
+ alias running lambda
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jonrowe-database_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 2
9
+ version: 0.5.2
10
+ platform: ruby
11
+ authors:
12
+ - Ben Mabey
13
+ - Jon Rowe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-04-06 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Strategies for cleaning databases. Can be used to ensure a clean state for testing.
23
+ email: mail@jonrowe.co.uk
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.textile
31
+ - TODO
32
+ files:
33
+ - History.txt
34
+ - README.textile
35
+ - Rakefile
36
+ - VERSION.yml
37
+ - cucumber.yml
38
+ - examples/features/example.feature
39
+ - examples/features/step_definitions/example_steps.rb
40
+ - examples/features/support/env.rb
41
+ - examples/lib/activerecord_models.rb
42
+ - examples/lib/couchpotato_models.rb
43
+ - examples/lib/datamapper_models.rb
44
+ - examples/lib/mongomapper_models.rb
45
+ - features/cleaning.feature
46
+ - features/step_definitions/database_cleaner_steps.rb
47
+ - features/support/env.rb
48
+ - lib/database_cleaner.rb
49
+ - lib/database_cleaner/active_record/transaction.rb
50
+ - lib/database_cleaner/active_record/truncation.rb
51
+ - lib/database_cleaner/configuration.rb
52
+ - lib/database_cleaner/couch_potato/truncation.rb
53
+ - lib/database_cleaner/cucumber.rb
54
+ - lib/database_cleaner/data_mapper/transaction.rb
55
+ - lib/database_cleaner/data_mapper/truncation.rb
56
+ - lib/database_cleaner/mongo_mapper/truncation.rb
57
+ - lib/database_cleaner/truncation_base.rb
58
+ - spec/database_cleaner/active_record/transaction_spec.rb
59
+ - spec/database_cleaner/active_record/truncation_spec.rb
60
+ - spec/database_cleaner/configuration_spec.rb
61
+ - spec/database_cleaner/couch_potato/truncation_spec.rb
62
+ - spec/database_cleaner/mongo_mapper/truncation_spec.rb
63
+ - spec/spec.opts
64
+ - spec/spec_helper.rb
65
+ - LICENSE
66
+ - TODO
67
+ has_rdoc: true
68
+ homepage: http://github.com/jonrowe/database_cleaner
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.6
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Strategies for cleaning databases. Can be used to ensure a clean state for testing.
97
+ test_files:
98
+ - spec/database_cleaner/active_record/transaction_spec.rb
99
+ - spec/database_cleaner/active_record/truncation_spec.rb
100
+ - spec/database_cleaner/configuration_spec.rb
101
+ - spec/database_cleaner/couch_potato/truncation_spec.rb
102
+ - spec/database_cleaner/mongo_mapper/truncation_spec.rb
103
+ - spec/spec_helper.rb
104
+ - examples/features/step_definitions/example_steps.rb
105
+ - examples/features/support/env.rb
106
+ - examples/lib/activerecord_models.rb
107
+ - examples/lib/couchpotato_models.rb
108
+ - examples/lib/datamapper_models.rb
109
+ - examples/lib/mongomapper_models.rb