mongo_doc 0.6.26 → 0.6.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +14 -203
- data/Rakefile +0 -134
- data/lib/mongo_doc/collection.rb +4 -0
- data/lib/mongo_doc/finders.rb +1 -0
- data/lib/mongo_doc/timestamps.rb +4 -3
- data/lib/mongo_doc/version.rb +3 -0
- data/lib/mongo_doc.rb +0 -5
- metadata +25 -212
- data/.document +0 -5
- data/.gitignore +0 -8
- data/.rspec +0 -2
- data/.rvmrc +0 -1
- data/.watchr +0 -32
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -72
- data/HISTORY.md +0 -11
- data/VERSION +0 -1
- data/examples/simple_document.rb +0 -46
- data/examples/simple_object.rb +0 -34
- data/features/collections.feature +0 -9
- data/features/connection.feature +0 -13
- data/features/db_references.feature +0 -21
- data/features/embed_hash.feature +0 -16
- data/features/finders.feature +0 -76
- data/features/indexes.feature +0 -28
- data/features/mongodb.yml +0 -7
- data/features/mongodoc_base.feature +0 -128
- data/features/new_record.feature +0 -36
- data/features/partial_updates.feature +0 -95
- data/features/polymorphic_collections.feature +0 -16
- data/features/references.feature +0 -28
- data/features/removing_documents.feature +0 -68
- data/features/saving_an_object.feature +0 -15
- data/features/scopes.feature +0 -66
- data/features/step_definitions/collection_steps.rb +0 -17
- data/features/step_definitions/connection_steps.rb +0 -13
- data/features/step_definitions/document_steps.rb +0 -155
- data/features/step_definitions/documents.rb +0 -61
- data/features/step_definitions/embed_hash_steps.rb +0 -6
- data/features/step_definitions/field_steps.rb +0 -28
- data/features/step_definitions/finder_steps.rb +0 -15
- data/features/step_definitions/index_steps.rb +0 -10
- data/features/step_definitions/json_steps.rb +0 -9
- data/features/step_definitions/object_steps.rb +0 -50
- data/features/step_definitions/objects.rb +0 -24
- data/features/step_definitions/partial_update_steps.rb +0 -31
- data/features/step_definitions/query_steps.rb +0 -69
- data/features/step_definitions/removing_documents_steps.rb +0 -14
- data/features/step_definitions/scope_steps.rb +0 -18
- data/features/step_definitions/string_casting_steps.rb +0 -29
- data/features/step_definitions/util_steps.rb +0 -7
- data/features/string_casting.feature +0 -10
- data/features/support/support.rb +0 -12
- data/features/timestamps.feature +0 -14
- data/features/using_criteria.feature +0 -148
- data/mongo_doc.gemspec +0 -272
- data/mongodb.example.yml +0 -14
- data/perf/mongo_doc_object.rb +0 -83
- data/perf/mongo_document.rb +0 -84
- data/perf/ruby_driver.rb +0 -49
- data/script/console +0 -8
- data/spec/active_model_behavior.rb +0 -64
- data/spec/array_including_argument_matcher.rb +0 -62
- data/spec/associations/collection_proxy_spec.rb +0 -233
- data/spec/associations/document_proxy_spec.rb +0 -45
- data/spec/associations/hash_proxy_spec.rb +0 -181
- data/spec/associations/proxy_base_spec.rb +0 -92
- data/spec/associations_spec.rb +0 -218
- data/spec/attributes_accessor_spec.rb +0 -39
- data/spec/attributes_spec.rb +0 -184
- data/spec/bson_matchers.rb +0 -54
- data/spec/bson_spec.rb +0 -196
- data/spec/collection_spec.rb +0 -169
- data/spec/connection_spec.rb +0 -169
- data/spec/contexts/ids_spec.rb +0 -49
- data/spec/contexts/mongo_spec.rb +0 -241
- data/spec/contexts_spec.rb +0 -56
- data/spec/criteria/optional_spec.rb +0 -26
- data/spec/criteria_spec.rb +0 -73
- data/spec/cursor_spec.rb +0 -91
- data/spec/database_cleaner_spec.rb +0 -24
- data/spec/document_ext.rb +0 -9
- data/spec/document_spec.rb +0 -569
- data/spec/embedded_save_spec.rb +0 -73
- data/spec/ext_spec.rb +0 -100
- data/spec/finders_spec.rb +0 -61
- data/spec/hash_matchers.rb +0 -29
- data/spec/index_spec.rb +0 -79
- data/spec/matchers_spec.rb +0 -342
- data/spec/mongodb.yml +0 -6
- data/spec/mongodb_pairs.yml +0 -8
- data/spec/new_record_spec.rb +0 -128
- data/spec/polymorphic_collection_spec.rb +0 -47
- data/spec/references_many_spec.rb +0 -214
- data/spec/references_spec.rb +0 -121
- data/spec/root_spec.rb +0 -41
- data/spec/scope_spec.rb +0 -88
- data/spec/spec_helper.rb +0 -16
- data/spec/timestamps_spec.rb +0 -154
- data/spec/update_spec.rb +0 -167
- data/spec/validations_spec.rb +0 -30
@@ -1,155 +0,0 @@
|
|
1
|
-
Given /^an empty (\w+) document collection$/ do |doc|
|
2
|
-
klass = doc.constantize
|
3
|
-
Given "an empty #{klass.collection_name} collection"
|
4
|
-
end
|
5
|
-
|
6
|
-
Given /^an? (\w+) document named '(.*)' :$/ do |doc, name, table|
|
7
|
-
@all = []
|
8
|
-
klass = doc.constantize
|
9
|
-
table.hashes.each do |hash|
|
10
|
-
@last = klass.new
|
11
|
-
hash.each do |attr, value|
|
12
|
-
@last.send("#{attr.underscore.gsub(' ', '_')}=", value)
|
13
|
-
end
|
14
|
-
@all << @last
|
15
|
-
end
|
16
|
-
instance_variable_set("@#{name}", @last)
|
17
|
-
end
|
18
|
-
|
19
|
-
Given /^'(.*)' has one (.*?) as (.*) :$/ do |doc_name, class_name, assoc_name, table|
|
20
|
-
doc = instance_variable_get("@#{doc_name}")
|
21
|
-
obj = class_name.constantize.new
|
22
|
-
table.hashes.each do |hash|
|
23
|
-
hash.each do |key, value|
|
24
|
-
obj.send("#{key.underscore.gsub(' ', '_')}=", value)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
doc.send("#{assoc_name.underscore.gsub(' ', '_')}=", obj)
|
28
|
-
@last = obj
|
29
|
-
end
|
30
|
-
|
31
|
-
Given /^'(.*)' has (?:a|an|many) (.*) :$/ do |doc_name, assoc_name, table|
|
32
|
-
doc = instance_variable_get("@#{doc_name}")
|
33
|
-
table.hashes.each do |hash|
|
34
|
-
doc.send(assoc_name).build(hash.inject({}) do |attrs, (attr, value)|
|
35
|
-
attrs["#{attr.underscore.gsub(' ', '_')}"] = value
|
36
|
-
attrs
|
37
|
-
end)
|
38
|
-
end
|
39
|
-
@all = doc.send(assoc_name)
|
40
|
-
@last = @all.last
|
41
|
-
end
|
42
|
-
|
43
|
-
Given /^I set the id on the document '(.*)' to (.*)$/ do |doc_name, value|
|
44
|
-
doc = instance_variable_get("@#{doc_name}")
|
45
|
-
doc._id = BSON::ObjectID.from_string("%024x" % value.to_i(16))
|
46
|
-
end
|
47
|
-
|
48
|
-
Given /^'(.+)' has one (.+?) as (.+?) \(identified by '(.+)'\):$/ do |doc_name, class_name, assoc_name, var_name, table|
|
49
|
-
doc = instance_variable_get("@#{doc_name}")
|
50
|
-
obj = class_name.constantize.new
|
51
|
-
table.hashes.each do |hash|
|
52
|
-
hash.each do |key, value|
|
53
|
-
obj.send("#{key.underscore.gsub(' ', '_')}=", value)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
instance_variable_set("@#{var_name}", obj)
|
57
|
-
doc.send("#{assoc_name.underscore.gsub(' ', '_')}=", obj)
|
58
|
-
@last = obj
|
59
|
-
end
|
60
|
-
|
61
|
-
When /^I save the document '(.*)'$/ do |name|
|
62
|
-
object = instance_variable_get("@#{name}")
|
63
|
-
@last_return = object.save
|
64
|
-
end
|
65
|
-
|
66
|
-
When /^I save the last document$/ do
|
67
|
-
@last_return = @last.save
|
68
|
-
end
|
69
|
-
|
70
|
-
When /^I create an (.*) '(.*)' from the hash '(.*)'$/ do |doc, name, hash|
|
71
|
-
klass = doc.constantize
|
72
|
-
attrs = instance_variable_get("@#{hash}")
|
73
|
-
instance_variable_set("@#{name}", klass.create(attrs))
|
74
|
-
end
|
75
|
-
|
76
|
-
When /^I update the document '(.*)' with the hash named '(.*)'$/ do |doc_name, hash_name|
|
77
|
-
doc = instance_variable_get("@#{doc_name}")
|
78
|
-
attrs = instance_variable_get("@#{hash_name}")
|
79
|
-
@last_return = doc.update_attributes(attrs)
|
80
|
-
end
|
81
|
-
|
82
|
-
When /^I query (.*) with criteria (.*)$/ do |doc, criteria_text|
|
83
|
-
klass = doc.singularize.camelize
|
84
|
-
@query = @last_return = eval("#{klass}.criteria.#{criteria_text}")
|
85
|
-
end
|
86
|
-
|
87
|
-
When /^I query (.*) with the '(.*)' id$/ do |doc, name|
|
88
|
-
klass = doc.singularize.camelize.constantize
|
89
|
-
doc = instance_variable_get("@#{name}")
|
90
|
-
@query = @last_return = klass.criteria.id(doc.id).entries
|
91
|
-
end
|
92
|
-
|
93
|
-
When /^I find a (.*) using the id of '(.*)'$/ do |type, doc_name|
|
94
|
-
klass = type.camelize.constantize
|
95
|
-
doc = instance_variable_get("@#{doc_name}")
|
96
|
-
@last_return = klass.find(doc.id)
|
97
|
-
end
|
98
|
-
|
99
|
-
When /^'(.+)' is the first (.+?) of '(.+)'$/ do |var_name, single_assoc, doc_name|
|
100
|
-
doc = instance_variable_get("@#{doc_name}")
|
101
|
-
instance_variable_set("@#{var_name}", doc.send(single_assoc.pluralize).first)
|
102
|
-
end
|
103
|
-
|
104
|
-
Then /^'(.*)' is not a new record$/ do |name|
|
105
|
-
instance_variable_get("@#{name}").new_record?.should be_false
|
106
|
-
end
|
107
|
-
|
108
|
-
Then /the (.*) collection should have (\d+) documents?/ do |doc, count|
|
109
|
-
klass = doc.constantize
|
110
|
-
klass.count.should == count.to_i
|
111
|
-
end
|
112
|
-
|
113
|
-
Then /^the document '(.*)' roundtrips$/ do |name|
|
114
|
-
object = instance_variable_get("@#{name}")
|
115
|
-
from_db = object.class.find_one(object._id)
|
116
|
-
from_db.should == object
|
117
|
-
instance_variable_set("@#{name}", from_db)
|
118
|
-
end
|
119
|
-
|
120
|
-
Then /^the document '(.+)' does not roundtrip$/ do |name|
|
121
|
-
object = instance_variable_get("@#{name}")
|
122
|
-
from_db = object.class.find_one(object._id)
|
123
|
-
from_db.should_not == object
|
124
|
-
end
|
125
|
-
|
126
|
-
Then /^the document '(\w+)' is reloaded$/ do |name|
|
127
|
-
object = instance_variable_get("@#{name}")
|
128
|
-
from_db = object.class.find_one(object._id)
|
129
|
-
instance_variable_set("@#{name}", from_db)
|
130
|
-
end
|
131
|
-
|
132
|
-
Then /^the last return value is (.+)$/ do |bool_val|
|
133
|
-
@last_return.should send("be_#{bool_val}")
|
134
|
-
end
|
135
|
-
|
136
|
-
Then /^the first (.*) of '(.*)' is not a new record$/ do |assoc, name|
|
137
|
-
object = instance_variable_get("@#{name}")
|
138
|
-
plural = assoc.pluralize
|
139
|
-
object.send(plural).first.should_not be_new_record
|
140
|
-
end
|
141
|
-
|
142
|
-
Then /^the (\w*) of '(.*)' is not a new record$/ do |assoc, name|
|
143
|
-
object = instance_variable_get("@#{name}")
|
144
|
-
object.send(assoc).should_not be_new_record
|
145
|
-
end
|
146
|
-
|
147
|
-
Then /^the (\w*) of '(.*)' roundtrips$/ do |assoc, name|
|
148
|
-
object = instance_variable_get("@#{name}")
|
149
|
-
from_db = object.class.find_one(object._id)
|
150
|
-
object.send(assoc).id.should == from_db.send(assoc).id
|
151
|
-
end
|
152
|
-
|
153
|
-
Then /^the size of the last return value is (.*)$/ do |count|
|
154
|
-
@last_return.size.should == count.to_i
|
155
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
class Address
|
2
|
-
include MongoDoc::Document
|
3
|
-
|
4
|
-
attr_accessor :street
|
5
|
-
attr_accessor :city
|
6
|
-
attr_accessor :state
|
7
|
-
attr_accessor :zip_code
|
8
|
-
end
|
9
|
-
|
10
|
-
class Place
|
11
|
-
include MongoDoc::Document
|
12
|
-
|
13
|
-
attr_accessor :name
|
14
|
-
attr_accessor :type
|
15
|
-
embed :address
|
16
|
-
end
|
17
|
-
|
18
|
-
class Contact
|
19
|
-
include MongoDoc::Document
|
20
|
-
|
21
|
-
attr_accessor :name
|
22
|
-
attr_accessor :type
|
23
|
-
attr_accessor :note
|
24
|
-
attr_accessor :interests
|
25
|
-
embed_many :addresses
|
26
|
-
|
27
|
-
scope :rubyists, any_in(:interests => ['ruby'])
|
28
|
-
scope :contract_work, any_in(:interests => ['contract work'])
|
29
|
-
scope :in_state, lambda {|state| where('addresses.state' => state)}
|
30
|
-
end
|
31
|
-
|
32
|
-
class Event
|
33
|
-
include MongoDoc::Document
|
34
|
-
|
35
|
-
attr_accessor :name
|
36
|
-
attr_accessor :venue
|
37
|
-
attr_accessor :date, :type => Date
|
38
|
-
|
39
|
-
embed_hash :addresses
|
40
|
-
end
|
41
|
-
|
42
|
-
class Person
|
43
|
-
include MongoDoc::Document
|
44
|
-
|
45
|
-
attr_accessor :name
|
46
|
-
references :address
|
47
|
-
references_many :addresses, :as => :previous_addresses
|
48
|
-
|
49
|
-
timestamps!
|
50
|
-
end
|
51
|
-
|
52
|
-
class VIP < Person
|
53
|
-
attr_accessor :title
|
54
|
-
end
|
55
|
-
|
56
|
-
class Character
|
57
|
-
include MongoDoc::Document
|
58
|
-
|
59
|
-
attr_accessor :name
|
60
|
-
references :as_ref => :address
|
61
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
Then /^the field (\w+) of the document '(\w+)' is not nil$/ do |field, name|
|
2
|
-
doc = instance_variable_get("@#{name}")
|
3
|
-
doc.send(field).should_not be_nil
|
4
|
-
end
|
5
|
-
|
6
|
-
When /^'(\w+)' references '(\w+)' as '(\w+)'$/ do |parent, child, field|
|
7
|
-
parent_doc = instance_variable_get("@#{parent}")
|
8
|
-
child_doc = instance_variable_get("@#{child}")
|
9
|
-
parent_doc.send("#{field}=", child_doc)
|
10
|
-
end
|
11
|
-
|
12
|
-
When /^'(\w+)' references '(\w+)' through '(\w+)'$/ do |parent, child, field|
|
13
|
-
parent_doc = instance_variable_get("@#{parent}")
|
14
|
-
child_doc = instance_variable_get("@#{child}")
|
15
|
-
parent_doc.send("#{field.singularize}_ids") << child_doc._id
|
16
|
-
end
|
17
|
-
|
18
|
-
Then /^'(\w+)' refers to '(\w+)' as '(\w+)'$/ do |name, other, field|
|
19
|
-
doc = instance_variable_get("@#{name}")
|
20
|
-
other_doc = instance_variable_get("@#{other}")
|
21
|
-
doc.send("#{field}").should == other_doc
|
22
|
-
end
|
23
|
-
|
24
|
-
Then /^'(\w+)' has '(\w+)' that include '(\w+)'$/ do |name, field, included|
|
25
|
-
doc = instance_variable_get("@#{name}")
|
26
|
-
included_doc = instance_variable_get("@#{included}")
|
27
|
-
doc.send("#{field}").should include(included_doc)
|
28
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
def finder_query=(finder)
|
2
|
-
@query = finder
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I query (.+) with (\w+)$/ do |doc, finder|
|
6
|
-
self.finder_query = klass(doc).send(finder)
|
7
|
-
end
|
8
|
-
|
9
|
-
When /^I query (.+) to find_one with the (.+) of the '(.+)' document$/ do |collection, id, doc_name|
|
10
|
-
self.finder_query = klass(collection).find_one(instance_variable_get("@#{doc_name}").send(id))
|
11
|
-
end
|
12
|
-
|
13
|
-
Then /^the query result (?:is|was) (\d+) documents$/ do |count|
|
14
|
-
query.should == count.to_i
|
15
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
When /^I create an index named (.*) on the (.*) collection$/ do |index_name, doc|
|
2
|
-
klass = doc.constantize
|
3
|
-
klass.index(index_name)
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /^there is an index on (.*) on the (.*) collection$/ do |index_name, doc|
|
7
|
-
klass = doc.constantize
|
8
|
-
klass.collection.index_information.should include("#{index_name}_1")
|
9
|
-
end
|
10
|
-
|
@@ -1,9 +0,0 @@
|
|
1
|
-
When /^I save the json '(\{.*\})'$/ do |json_text|
|
2
|
-
json = JSON.parse(json_text)
|
3
|
-
@last_save = @collection.save(json)
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /^the json '(\{.*\})' roundtrips$/ do |json_text|
|
7
|
-
json = JSON.parse(json_text)
|
8
|
-
@collection.find_one(@last_save).should be_mongo_eql(json, false)
|
9
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
Given /^an object '(.*)'$/ do |name|
|
2
|
-
@movie = Movie.new
|
3
|
-
@movie.title = 'Gone with the Wind'
|
4
|
-
@movie.director = 'Victor Fleming'
|
5
|
-
@movie.writers = ['Sidney Howard']
|
6
|
-
@director = Director.new
|
7
|
-
@director.name = 'Victor Fleming'
|
8
|
-
@award = AcademyAward.new
|
9
|
-
@award.year = '1940'
|
10
|
-
@award.category = 'Best Director'
|
11
|
-
@director.awards = [@award]
|
12
|
-
@movie.director = @director
|
13
|
-
end
|
14
|
-
|
15
|
-
Given /^a hash named '(.*)':$/ do |name, table|
|
16
|
-
@all = []
|
17
|
-
table.hashes.each do |hash|
|
18
|
-
@last = hash.inject({}) do |h, (key, value)|
|
19
|
-
h["#{key.underscore.gsub(' ', '_')}"] = value
|
20
|
-
h
|
21
|
-
end
|
22
|
-
@all << @last
|
23
|
-
end
|
24
|
-
instance_variable_set("@#{name}", @last)
|
25
|
-
end
|
26
|
-
|
27
|
-
Given /^'(.*)' has (.*), an array of:$/ do |name, attribute, table|
|
28
|
-
object = instance_variable_get("@#{name}")
|
29
|
-
object.send(attribute + "=", [])
|
30
|
-
table.hashes.each do |hash|
|
31
|
-
hash.each {|key, value| object.send(attribute) << value}
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
When /^I save the object '(.*)'$/ do |name|
|
37
|
-
object = instance_variable_get("@#{name}")
|
38
|
-
@last_save = @collection.save(object)
|
39
|
-
end
|
40
|
-
|
41
|
-
Then /^the object '(.*)' roundtrips$/ do |name|
|
42
|
-
object = instance_variable_get("@#{name}")
|
43
|
-
object.instance_variable_set("@_id", @last_save)
|
44
|
-
@collection.find_one(@last_save).should == object
|
45
|
-
end
|
46
|
-
|
47
|
-
Then /^the attribute '(.*)' of '(.*)' is '(.*)'$/ do |attr, var, value|
|
48
|
-
object = instance_variable_get("@#{var}")
|
49
|
-
object.send(attr).to_s.should == value
|
50
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ValueEquals
|
2
|
-
def ==(other)
|
3
|
-
return false unless instance_variables.size == other.instance_variables.size
|
4
|
-
instance_variables.all? {|var| self.instance_variable_get(var) == other.instance_variable_get(var)}
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class Movie
|
9
|
-
include ValueEquals
|
10
|
-
|
11
|
-
attr_accessor :title, :director, :writers
|
12
|
-
end
|
13
|
-
|
14
|
-
class Director
|
15
|
-
include ValueEquals
|
16
|
-
|
17
|
-
attr_accessor :name, :awards
|
18
|
-
end
|
19
|
-
|
20
|
-
class AcademyAward
|
21
|
-
include ValueEquals
|
22
|
-
|
23
|
-
attr_accessor :year, :category
|
24
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
When /^I update the '(.+)' for '(.+)' to '(.+)'$/ do |attr, doc_name, value|
|
2
|
-
doc = instance_variable_get("@#{doc_name}")
|
3
|
-
attrs = {attr => value}
|
4
|
-
@last_return = doc.update_attributes(attrs)
|
5
|
-
end
|
6
|
-
|
7
|
-
When /^someone else changes the (.+?) '(.+)' of '(.+)' to$/ do |assoc_klass, assoc_name, name, table|
|
8
|
-
orig = instance_variable_get("@#{name}")
|
9
|
-
doc = orig.class.find_one(orig._id)
|
10
|
-
obj = assoc_klass.constantize.new
|
11
|
-
table.hashes.each do |hash|
|
12
|
-
hash.each do |key, value|
|
13
|
-
obj.send("#{key.underscore.gsub(' ', '_')}=", value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
doc.send("#{assoc_name.underscore.gsub(' ', '_')}=", obj)
|
17
|
-
doc.save
|
18
|
-
end
|
19
|
-
|
20
|
-
When /^someone else changes the (.+) of '(.+)':$/ do |assoc_name, name, table|
|
21
|
-
orig = instance_variable_get("@#{name}")
|
22
|
-
doc = orig.class.find_one(orig._id)
|
23
|
-
doc.send(assoc_name).clear
|
24
|
-
table.hashes.each do |hash|
|
25
|
-
doc.send(assoc_name) << hash.inject({}) do |attrs, (attr, value)|
|
26
|
-
attrs["#{attr.underscore.gsub(' ', '_')}"] = value
|
27
|
-
attrs
|
28
|
-
end
|
29
|
-
end
|
30
|
-
doc.save
|
31
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
def klass(klass_name = nil)
|
2
|
-
@klass ||= klass_name.singularize.camelize.constantize
|
3
|
-
end
|
4
|
-
|
5
|
-
def query(klass_name = nil)
|
6
|
-
@query ||= klass(klass_name).criteria
|
7
|
-
end
|
8
|
-
|
9
|
-
When "I also want a $number query with criteria $criteria" do |number, criteria|
|
10
|
-
instance_variable_set("@#{number}", eval("query.#{criteria}"))
|
11
|
-
end
|
12
|
-
|
13
|
-
When /^I requery$/ do
|
14
|
-
# do nothing
|
15
|
-
end
|
16
|
-
|
17
|
-
Then /^the query result is equal to the document '(.*)'$/ do |name|
|
18
|
-
doc = instance_variable_get("@#{name}")
|
19
|
-
query.should == doc
|
20
|
-
end
|
21
|
-
|
22
|
-
Then /^one of the query results is the document '(.*)'$/ do |name|
|
23
|
-
doc = instance_variable_get("@#{name}")
|
24
|
-
query.any? {|d| d == doc}.should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
Then /^the query result with "(.*)" == "(.*)" has a count of (.*)$/ do |key, value, count|
|
28
|
-
query.find {|r| r.has_key?(key) and r[key] == value }['count'].should == count.to_i
|
29
|
-
end
|
30
|
-
|
31
|
-
Then /^the query result with "([^\"]*)" == "([^\"]*)" has the document '(.*)'$/ do |key, value, name|
|
32
|
-
doc = instance_variable_get("@#{name}")
|
33
|
-
query.find {|r| r.has_key?(key) and r[key] == value }['group'].should include(doc)
|
34
|
-
end
|
35
|
-
|
36
|
-
Then /^the query result has (.*) documents*$/ do |count|
|
37
|
-
if query.respond_to?(:size)
|
38
|
-
query.size.should == count.to_i
|
39
|
-
else
|
40
|
-
query.count.should == count.to_i
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
Then /^the (first|last) query result is the document '(.*)'$/ do |position, name|
|
45
|
-
doc = instance_variable_get("@#{name}")
|
46
|
-
query.entries.send(position).should == doc
|
47
|
-
end
|
48
|
-
|
49
|
-
Then /^the size of the query result is (.*)$/ do |count|
|
50
|
-
query.to_a.size.should == count.to_i
|
51
|
-
end
|
52
|
-
|
53
|
-
Then /^the query result is the document '(.*)'$/ do |name|
|
54
|
-
object = instance_variable_get("@#{name}")
|
55
|
-
if query.kind_of?(Array)
|
56
|
-
query.size.should == 1
|
57
|
-
query.first.should == object
|
58
|
-
else
|
59
|
-
query.should == object
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
Then /^the query (is|is not) (empty|blank)$/ do |is, empty|
|
64
|
-
query.send("#{empty}?").should == (is == 'is')
|
65
|
-
end
|
66
|
-
|
67
|
-
Then /^the (.+) query (is|is not) (empty|blank)$/ do |number, is, empty|
|
68
|
-
instance_variable_get("@#{number}").send("#{empty}?").should == (is == 'is')
|
69
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
When /^I remove '(.+)'$/ do |doc_name|
|
2
|
-
doc = instance_variable_get("@#{doc_name}")
|
3
|
-
doc.remove
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /^the document '(.+)' is not found$/ do |doc_name|
|
7
|
-
doc = instance_variable_get("@#{doc_name}")
|
8
|
-
doc.class.find_one(doc.id)
|
9
|
-
end
|
10
|
-
|
11
|
-
Then /^an exception is raised if I remove '(.+)'$/ do |doc_name|
|
12
|
-
doc = instance_variable_get("@#{doc_name}")
|
13
|
-
lambda { doc.remove }.should raise_error
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
def scope_query=(scope)
|
2
|
-
@query = scope
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I query (.*) with scope '(.*)'$/ do |doc, scope|
|
6
|
-
self.scope_query = klass(doc).send(scope)
|
7
|
-
end
|
8
|
-
|
9
|
-
When /^I query (.*) with scopes '(.*)'$/ do |doc, scopes|
|
10
|
-
self.scope_query = scopes.split(',').inject(klass(doc)) do |result, scope|
|
11
|
-
result.send(scope.strip)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
When /^I query (.*) with lambda scope '(.*)' with parameters '(.*)'$/ do |doc, scope, params_text|
|
16
|
-
params = params_text.split(',').map(&:strip)
|
17
|
-
self.scope_query = klass(doc).send(scope, *params)
|
18
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
def last
|
2
|
-
@last
|
3
|
-
end
|
4
|
-
|
5
|
-
def last=(value)
|
6
|
-
@last = value
|
7
|
-
end
|
8
|
-
|
9
|
-
def all
|
10
|
-
@all ||= []
|
11
|
-
end
|
12
|
-
|
13
|
-
def all=(value)
|
14
|
-
@all = value
|
15
|
-
end
|
16
|
-
|
17
|
-
Given /^a class (.+)$/ do |type_name|
|
18
|
-
type_name.constantize.should be_kind_of(Class)
|
19
|
-
end
|
20
|
-
|
21
|
-
Given /^I create an (.+) '(.+)' with:$/ do |klass_name, object_name, table|
|
22
|
-
Given "an #{klass_name} document named '#{object_name}' :", table
|
23
|
-
end
|
24
|
-
|
25
|
-
Then /^the object '(.+)' has an attribute '(.+)' of type (.*)$/ do |object_name, attr_name, type_name|
|
26
|
-
object = instance_variable_get("@#{object_name}")
|
27
|
-
type_name.constantize.should === object.send(attr_name)
|
28
|
-
end
|
29
|
-
|
@@ -1,10 +0,0 @@
|
|
1
|
-
Feature: String casting
|
2
|
-
|
3
|
-
Background:
|
4
|
-
Given a class Event
|
5
|
-
|
6
|
-
Scenario: Creating a new document
|
7
|
-
When I create an Event 'event' with:
|
8
|
-
| Name | Venue | Date |
|
9
|
-
| NoSQL Live | John Hancock Conference Center | 2010-03-11 |
|
10
|
-
Then the object 'event' has an attribute 'date' of type Date
|
data/features/support/support.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..'))
|
3
|
-
require 'cucumber'
|
4
|
-
require 'rspec/expectations'
|
5
|
-
require 'spec/bson_matchers'
|
6
|
-
require 'mongo_doc'
|
7
|
-
require 'active_support/json'
|
8
|
-
|
9
|
-
MongoDoc::Connection.env = 'cucumber'
|
10
|
-
MongoDoc::Connection.config_path = './features/mongodb.yml'
|
11
|
-
|
12
|
-
World(BsonMatchers)
|
data/features/timestamps.feature
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
Feature: Timestamps
|
2
|
-
|
3
|
-
Background:
|
4
|
-
Given an empty Person document collection
|
5
|
-
And a Person document named 'Fry' :
|
6
|
-
| Name |
|
7
|
-
| Philip J. Fry |
|
8
|
-
|
9
|
-
Scenario: Creation time
|
10
|
-
When I save the document 'Fry'
|
11
|
-
And the document 'Fry' is reloaded
|
12
|
-
Then the field created_at of the document 'Fry' is not nil
|
13
|
-
And the field updated_at of the document 'Fry' is not nil
|
14
|
-
|