mongo-fixture 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/features/play_around_with_fixtures.feature +31 -0
- data/features/stepdefs/play_around_with_fixtures/create_a_simple_fixture_push_it_and_rollback.rb +1 -2
- data/features/support/hooks.rb +1 -1
- data/lib/mongo-fixture.rb +12 -9
- data/lib/mongo-fixture/version.rb +1 -1
- data/spec/mongo/cross_references_spec.rb +39 -0
- data/spec/mongo/fixture_spec.rb +37 -1
- metadata +5 -3
@@ -82,3 +82,34 @@ Scenario: I save the done fixtures so to perform the rollbacks later
|
|
82
82
|
When I stash the fixture as done
|
83
83
|
And I rollback the stashed fixtures
|
84
84
|
Then I should see 0 records in users
|
85
|
+
|
86
|
+
Scenario: References across collections
|
87
|
+
Given a collection users
|
88
|
+
And a collection sessions
|
89
|
+
And a file "test/fixtures/references/users.yaml" with:
|
90
|
+
"""
|
91
|
+
pepe:
|
92
|
+
username: pepe
|
93
|
+
password:
|
94
|
+
raw: secreto
|
95
|
+
processed: 252db48960f032db4bb604bc26f97106fa85ff88dedef3a28671b6bcd9f9644bf90d7e444d587c9351dfa237a6fc8fe38641a8469d084a166c7807d9c6564860
|
96
|
+
name: Pepe
|
97
|
+
"""
|
98
|
+
And a file "test/fixtures/references/sessions.yaml" with:
|
99
|
+
"""
|
100
|
+
14_horas:
|
101
|
+
user:
|
102
|
+
users: pepe
|
103
|
+
time: 2012-07-30T14:02:40-03:00
|
104
|
+
y_tres_minutos:
|
105
|
+
user:
|
106
|
+
users: pepe
|
107
|
+
time: 2012-07-30T14:03:40-03:00
|
108
|
+
y_cuatro_minutos:
|
109
|
+
user:
|
110
|
+
users: pepe
|
111
|
+
time: 2012-07-30T14:04:40-03:00
|
112
|
+
"""
|
113
|
+
And I load the references fixture
|
114
|
+
Then I should see 1 record in users with username "pepe" and name "Pepe"
|
115
|
+
And I should see 3 records in sessions
|
data/features/stepdefs/play_around_with_fixtures/create_a_simple_fixture_push_it_and_rollback.rb
CHANGED
@@ -37,7 +37,7 @@ And /^a file "(.+?)" with:$/ do |file, content|
|
|
37
37
|
end
|
38
38
|
|
39
39
|
When /^I load the (\w+) fixture$/ do |fixture|
|
40
|
-
#
|
40
|
+
#binding.pry
|
41
41
|
@fixture = Mongo::Fixture.new fixture.to_sym, @DB
|
42
42
|
end
|
43
43
|
|
@@ -66,4 +66,3 @@ end
|
|
66
66
|
Then /^I should see (\d+) records in (\w+)$/ do |amount, collection|
|
67
67
|
@DB[collection].count.should == amount.to_i
|
68
68
|
end
|
69
|
-
|
data/features/support/hooks.rb
CHANGED
data/lib/mongo-fixture.rb
CHANGED
@@ -90,15 +90,16 @@ module Mongo
|
|
90
90
|
check
|
91
91
|
|
92
92
|
@data.each do |collection, matrix|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
93
|
+
unless data_was_inserted_in? collection
|
94
|
+
matrix.each do |element, values|
|
95
|
+
begin
|
96
|
+
@connection[collection].insert simplify values.to_hash
|
97
|
+
rescue MissingProcessedValueError => m
|
98
|
+
rollback
|
99
|
+
raise MissingProcessedValueError, "In record '#{element}' to be inserted into '#{collection}', the processed value of field '#{m.field}' is missing, aborting"
|
100
|
+
end
|
101
101
|
end
|
102
|
+
@inserted << collection
|
102
103
|
end
|
103
104
|
end
|
104
105
|
end
|
@@ -128,7 +129,9 @@ module Mongo
|
|
128
129
|
unless data_was_inserted_in? actual_option
|
129
130
|
insert_data_for actual_option
|
130
131
|
end
|
131
|
-
|
132
|
+
current_collection = @connection[actual_option]
|
133
|
+
current_data = simplify @data[actual_option][value[actual_option].to_sym]
|
134
|
+
the_returned_hash[key] = current_collection.find(current_data).first["_id"]
|
132
135
|
end
|
133
136
|
else
|
134
137
|
the_returned_hash[key] = value
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "mongo-fixture"
|
2
|
+
|
3
|
+
describe Mongo::Fixture do
|
4
|
+
context "two collections are to be inserted with references" do
|
5
|
+
before do
|
6
|
+
Fast.file.write "test/fixtures/references/users.yaml", "pepe:
|
7
|
+
username: pepe
|
8
|
+
password:
|
9
|
+
raw: secreto
|
10
|
+
processed: 252db48960f032db4bb604bc26f97106fa85ff88dedef3a28671b6bcd9f9644bf90d7e444d587c9351dfa237a6fc8fe38641a8469d084a166c7807d9c6564860
|
11
|
+
name: Pepe"
|
12
|
+
Fast.file.write "test/fixtures/references/sessions.yaml", "14_horas:
|
13
|
+
user:
|
14
|
+
users: pepe
|
15
|
+
time: 2012-07-30T14:02:40-03:00
|
16
|
+
y_tres_minutos:
|
17
|
+
user:
|
18
|
+
users: pepe
|
19
|
+
time: 2012-07-30T14:03:40-03:00
|
20
|
+
y_cuatro_minutos:
|
21
|
+
user:
|
22
|
+
users: pepe
|
23
|
+
time: 2012-07-30T14:04:40-03:00"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not fail!" do
|
27
|
+
collection = double 'coll', :count => 0, :insert => nil
|
28
|
+
database = double 'database'
|
29
|
+
database.stub :[] do |argument|
|
30
|
+
collection
|
31
|
+
end
|
32
|
+
Mongo::Fixture.new :references, database
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
Fast.dir.remove! :test
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/mongo/fixture_spec.rb
CHANGED
@@ -437,7 +437,7 @@ describe Mongo::Fixture do
|
|
437
437
|
comm = double 'comments', :count => 0, :drop => nil
|
438
438
|
comm.should_receive( :insert ).with( :user => "un id", :text => "FLAME" )
|
439
439
|
record = stub 'record'
|
440
|
-
record.should_receive( :[] ).with(
|
440
|
+
record.should_receive( :[] ).with( "_id" ).and_return "un id"
|
441
441
|
usrs = double 'users', :count => 0, :find => stub( :first => record ), :drop => nil, :insert => nil
|
442
442
|
database.stub :[] do |coll|
|
443
443
|
case coll
|
@@ -632,4 +632,40 @@ describe Mongo::Fixture do
|
|
632
632
|
end
|
633
633
|
end
|
634
634
|
end
|
635
|
+
|
636
|
+
context "two collections are to be inserted with references" do
|
637
|
+
before do
|
638
|
+
Fast.file.write "test/fixtures/references/users.yaml", "pepe:
|
639
|
+
username: pepe
|
640
|
+
password:
|
641
|
+
raw: secreto
|
642
|
+
processed: 252db48960f032db4bb604bc26f97106fa85ff88dedef3a28671b6bcd9f9644bf90d7e444d587c9351dfa237a6fc8fe38641a8469d084a166c7807d9c6564860
|
643
|
+
name: Pepe"
|
644
|
+
Fast.file.write "test/fixtures/references/sessions.yaml", "14_horas:
|
645
|
+
user:
|
646
|
+
users: pepe
|
647
|
+
time: 2012-07-30T14:02:40-03:00
|
648
|
+
y_tres_minutos:
|
649
|
+
user:
|
650
|
+
users: pepe
|
651
|
+
time: 2012-07-30T14:03:40-03:00
|
652
|
+
y_cuatro_minutos:
|
653
|
+
user:
|
654
|
+
users: pepe
|
655
|
+
time: 2012-07-30T14:04:40-03:00"
|
656
|
+
end
|
657
|
+
|
658
|
+
it "should not fail!" do
|
659
|
+
collection = double 'coll', :count => 0, :insert => nil
|
660
|
+
database = double 'database'
|
661
|
+
database.stub :[] do |argument|
|
662
|
+
collection
|
663
|
+
end
|
664
|
+
Mongo::Fixture.new :references, database
|
665
|
+
end
|
666
|
+
|
667
|
+
after do
|
668
|
+
Fast.dir.remove! :test
|
669
|
+
end
|
670
|
+
end
|
635
671
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo-fixture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/mongo-fixture.rb
|
100
100
|
- lib/mongo-fixture/version.rb
|
101
101
|
- mongo-fixture.gemspec
|
102
|
+
- spec/mongo/cross_references_spec.rb
|
102
103
|
- spec/mongo/fixture_spec.rb
|
103
104
|
homepage: http://github.com/Fetcher/mongo-fixture
|
104
105
|
licenses: []
|
@@ -114,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
115
|
version: '0'
|
115
116
|
segments:
|
116
117
|
- 0
|
117
|
-
hash: -
|
118
|
+
hash: -277568515
|
118
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
120
|
none: false
|
120
121
|
requirements:
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: '0'
|
124
125
|
segments:
|
125
126
|
- 0
|
126
|
-
hash: -
|
127
|
+
hash: -277568515
|
127
128
|
requirements: []
|
128
129
|
rubyforge_project:
|
129
130
|
rubygems_version: 1.8.24
|
@@ -138,4 +139,5 @@ test_files:
|
|
138
139
|
- features/stepdefs/play_around_with_fixtures/misconfigured_password_field.rb
|
139
140
|
- features/support/env.rb
|
140
141
|
- features/support/hooks.rb
|
142
|
+
- spec/mongo/cross_references_spec.rb
|
141
143
|
- spec/mongo/fixture_spec.rb
|