active_repository 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,42 @@
1
1
  require 'set'
2
2
 
3
- shared_examples ".update_attributes" do
3
+ shared_examples ".serialized_attributes" do
4
+ it "returns class name" do
5
+ Country.serialized_attributes.should == ["name", "monarch", "language", "created_at", "updated_at"]
6
+ end
7
+ end
8
+
9
+ shared_examples ".constantize" do
10
+ it "returns class name" do
11
+ Country.constantize.should == Country
12
+ end
13
+ end
14
+
15
+ shared_examples ".update_attribute" do
4
16
  it "updates records" do
5
17
  id = Country.first.id
6
18
  country = Country.find(id)
7
- country.update_attributes(:name => "Italy")
19
+ country.update_attribute(:name, "Italy")
8
20
 
9
21
  Country.first.name.should == "Italy"
10
22
  end
11
23
 
12
- it "must not update id" do
24
+ it "updates records whit string keys" do
13
25
  id = Country.first.id
14
26
  country = Country.find(id)
27
+ country.update_attribute('name', "Germany")
15
28
 
16
- country.update_attributes(:id => 45, :name => "Russia")
29
+ Country.first.name.should == "Germany"
30
+ end
31
+ end
32
+
33
+ shared_examples ".update_attributes" do
34
+ it "updates records" do
35
+ id = Country.first.id
36
+ country = Country.find(id)
37
+ country.update_attributes(:name => "Italy")
17
38
 
18
- Country.first.name.should == "Russia"
19
- Country.first.id.should_not == 45
39
+ Country.first.name.should == "Italy"
20
40
  end
21
41
 
22
42
  it "updates records whit string keys" do
@@ -54,34 +74,27 @@ shared_examples ".where" do
54
74
  end
55
75
 
56
76
  it "returns all data as inflated objects" do
57
- Country.where(:language => 'English', :name => 'US').all? { |country| country.should be_kind_of(Country) }
77
+ expect(Country.where(:language => 'English', :name => 'US')).to be_a ActiveRepository::ResultSet
58
78
  end
59
79
 
60
80
  it "populates the data correctly" do
61
81
  first_id = Country.first.id
62
82
  last_id = Country.all[3].id
63
83
 
64
- records = Country.where(:language => 'English')
65
- records.first.id.should == first_id
66
- records.first.name.should == "US"
67
- records.last.id.should == last_id
68
- records.last.name.should == "UK"
84
+ results = Country.where(:language => 'English').all
85
+ results.first.id.should == first_id
86
+ results.first.name.should == "US"
87
+ results.last.id.should == last_id
88
+ results.last.name.should == "UK"
69
89
  end
70
90
 
71
91
  it "filters the records from a AR-like conditions hash" do
72
92
  first_id = Country.first.id
73
93
 
74
- record = Country.where(:name => 'US')
75
- record.count.should == 1
76
- record.first.id.should == first_id
77
- record.first.name.should == 'US'
78
- end
79
-
80
- it "if id exists, use auto increment id" do
81
- first_id = Country.first.id
82
- country = Country.create(:name => "Russia", :language => 'Russian')
83
-
84
- country.id.should_not == first_id
94
+ results = Country.where(:name => 'US').all
95
+ results.count.should == 1
96
+ results.first.id.should == first_id
97
+ results.first.name.should == 'US'
85
98
  end
86
99
  end
87
100
 
@@ -141,16 +154,6 @@ shared_examples ".find" do
141
154
  end
142
155
  end
143
156
 
144
- context "with :all" do
145
- it "returns all records" do
146
- records = Country.find(:all)
147
-
148
- records.should include(Country.first)
149
- records.should include(Country.last)
150
- records.size.should == 5
151
- end
152
- end
153
-
154
157
  context "with an array of ids" do
155
158
  it "returns all matching ids" do
156
159
  countries = Country.all
@@ -166,28 +169,84 @@ shared_examples ".find" do
166
169
  end
167
170
  end
168
171
 
169
- shared_examples ".find_by_id" do
172
+ shared_examples ".find_by" do
173
+ context "with an id" do
174
+ it "finds the record with the specified id" do
175
+ id = Country.all[1].id
176
+ Country.find_by(id: id).id.should == id
177
+ end
178
+
179
+ it "finds the record with the specified id as a string" do
180
+ id = Country.all[1].id
181
+ Country.find_by(id: id.to_s).id.should == id
182
+ end
183
+ end
184
+
185
+ context "with nil" do
186
+ it "returns nil" do
187
+ Country.find_by(id: nil).should be_nil
188
+ end
189
+ end
190
+
191
+ context "with an id not present" do
192
+ it "returns nil" do
193
+ Country.find_by(id: 4567).should be_nil
194
+ end
195
+ end
196
+
197
+ context 'with a existing name' do
198
+ it "returns found element" do
199
+ Country.find_by(name: 'Canada').should == Country.all[1]
200
+ end
201
+ end
202
+
203
+ context 'with a not existing name' do
204
+ it "returns found element" do
205
+ Country.find_by(name: 'China').should be_nil
206
+ end
207
+ end
208
+ end
209
+
210
+ shared_examples ".find_by!" do
170
211
  context "with an id" do
171
212
  it "finds the record with the specified id" do
172
213
  id = Country.all[1].id
173
- Country.find_by_id(id).id.should == id
214
+ Country.find_by!(id: id).id.should == id
174
215
  end
175
216
 
176
217
  it "finds the record with the specified id as a string" do
177
218
  id = Country.all[1].id
178
- Country.find_by_id(id.to_s).id.should == id
219
+ Country.find_by!(id: id.to_s).id.should == id
179
220
  end
180
221
  end
181
222
 
182
223
  context "with nil" do
183
224
  it "returns nil" do
184
- Country.find_by_id(nil).should be_nil
225
+ lambda {
226
+ Country.find_by!(id: nil)
227
+ }.should raise_error(ActiveHash::RecordNotFound)
185
228
  end
186
229
  end
187
230
 
188
231
  context "with an id not present" do
189
232
  it "returns nil" do
190
- Country.find_by_id(4567).should be_nil
233
+ lambda {
234
+ Country.find_by!(id: 4567)
235
+ }.should raise_error(ActiveHash::RecordNotFound)
236
+ end
237
+ end
238
+
239
+ context 'with a existing name' do
240
+ it "returns found element" do
241
+ Country.find_by!(name: 'Canada').should == Country.all[1]
242
+ end
243
+ end
244
+
245
+ context 'with a not existing name' do
246
+ it "returns found element" do
247
+ lambda {
248
+ Country.find_by!(name: 'China')
249
+ }.should raise_error(ActiveHash::RecordNotFound)
191
250
  end
192
251
  end
193
252
  end
@@ -563,7 +622,7 @@ shared_examples ".create" do
563
622
 
564
623
  country2 = Country.new :name => "bar"
565
624
  country2.save
566
- country2.id.should == ((country1.id.class.name == "Moped::BSON::ObjectId") ? country2.id : country1.id + 1)
625
+ country2.id.should == ((["BSON::ObjectId", "Moped::BSON::ObjectId"].include?(country1.id.class.name)) ? country2.id : country1.id + 1)
567
626
  end
568
627
 
569
628
  it "adds the new object to the data collection" do
@@ -647,11 +706,11 @@ shared_examples "#delete" do
647
706
  it "removes a record" do
648
707
  country = Country.create
649
708
 
650
- Country.size.should == 1
709
+ Country.count.should == 1
651
710
 
652
711
  country.delete
653
712
 
654
- Country.size.should == 0
713
+ Country.count.should == 0
655
714
  end
656
715
  end
657
716
 
metadata CHANGED
@@ -1,158 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_repository
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Caio Torres
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-18 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: active_hash
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: 0.9.12
19
+ version: 1.2.3
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: 0.9.12
26
+ version: 1.2.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activemodel
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
- version: 3.2.6
33
+ version: '3.2'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
- version: 3.2.6
40
+ version: '3.2'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: sql_query_executor
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
- version: 0.0.1
47
+ version: 0.3.1
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
- version: 0.0.1
54
+ version: 0.3.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: rspec
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ! '>='
73
+ - - '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: 2.2.0
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ! '>='
80
+ - - '>='
76
81
  - !ruby/object:Gem::Version
77
82
  version: 2.2.0
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: activerecord
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ! '>='
87
+ - - '>='
84
88
  - !ruby/object:Gem::Version
85
- version: 3.2.6
89
+ version: '3.2'
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ! '>='
94
+ - - '>='
92
95
  - !ruby/object:Gem::Version
93
- version: 3.2.6
96
+ version: '3.2'
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: mongoid
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ! '>='
101
+ - - '>='
100
102
  - !ruby/object:Gem::Version
101
- version: 3.0.11
103
+ version: '3.1'
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
- - - ! '>='
108
+ - - '>='
108
109
  - !ruby/object:Gem::Version
109
- version: 3.0.11
110
+ version: '3.1'
110
111
  - !ruby/object:Gem::Dependency
111
112
  name: rake
112
113
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: 10.0.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
121
  requirements:
123
- - - ! '>='
122
+ - - '>='
124
123
  - !ruby/object:Gem::Version
125
124
  version: 10.0.0
126
125
  - !ruby/object:Gem::Dependency
127
126
  name: coveralls
128
127
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
- - - ! '>='
129
+ - - '>='
132
130
  - !ruby/object:Gem::Version
133
131
  version: '0'
134
132
  type: :development
135
133
  prerelease: false
136
134
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
135
  requirements:
139
- - - ! '>='
136
+ - - '>='
140
137
  - !ruby/object:Gem::Version
141
138
  version: '0'
142
139
  - !ruby/object:Gem::Dependency
143
140
  name: sqlite3
144
141
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
142
  requirements:
147
- - - ! '>='
143
+ - - '>='
148
144
  - !ruby/object:Gem::Version
149
145
  version: '0'
150
146
  type: :development
151
147
  prerelease: false
152
148
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
149
  requirements:
155
- - - ! '>='
150
+ - - '>='
156
151
  - !ruby/object:Gem::Version
157
152
  version: '0'
158
153
  description: An implementation of repository pattern that can connect with any ORM
@@ -165,13 +160,13 @@ files:
165
160
  - LICENSE
166
161
  - README.md
167
162
  - active_repository.gemspec
168
- - lib/active_repository/adapters/active_hash_adapter.rb
169
163
  - lib/active_repository/adapters/default_adapter.rb
170
164
  - lib/active_repository/adapters/mongoid_adapter.rb
171
165
  - lib/active_repository/adapters/persistence_adapter.rb
172
166
  - lib/active_repository/associations.rb
173
167
  - lib/active_repository/base.rb
174
168
  - lib/active_repository/finders.rb
169
+ - lib/active_repository/result_set.rb
175
170
  - lib/active_repository/uniqueness.rb
176
171
  - lib/active_repository/version.rb
177
172
  - lib/active_repository/write_support.rb
@@ -180,36 +175,37 @@ files:
180
175
  - Gemfile
181
176
  - spec/active_repository/base_spec.rb
182
177
  - spec/active_repository/associations_spec.rb
178
+ - spec/active_repository/result_set_spec.rb
183
179
  - spec/support/shared_examples.rb
184
180
  - spec/spec_helper.rb
185
181
  homepage: http://github.com/efreesen/active_repository
186
182
  licenses:
187
183
  - GPL
184
+ metadata: {}
188
185
  post_install_message:
189
186
  rdoc_options: []
190
187
  require_paths:
191
188
  - lib
192
189
  required_ruby_version: !ruby/object:Gem::Requirement
193
- none: false
194
190
  requirements:
195
- - - ! '>='
191
+ - - '>='
196
192
  - !ruby/object:Gem::Version
197
193
  version: '0'
198
194
  required_rubygems_version: !ruby/object:Gem::Requirement
199
- none: false
200
195
  requirements:
201
- - - ! '>='
196
+ - - '>='
202
197
  - !ruby/object:Gem::Version
203
198
  version: '0'
204
199
  requirements: []
205
200
  rubyforge_project:
206
- rubygems_version: 1.8.23
201
+ rubygems_version: 2.0.14
207
202
  signing_key:
208
- specification_version: 3
203
+ specification_version: 4
209
204
  summary: An implementation of repository pattern that can connect with any ORM
210
205
  test_files:
211
206
  - Gemfile
212
207
  - spec/active_repository/base_spec.rb
213
208
  - spec/active_repository/associations_spec.rb
209
+ - spec/active_repository/result_set_spec.rb
214
210
  - spec/support/shared_examples.rb
215
211
  - spec/spec_helper.rb
@@ -1,20 +0,0 @@
1
- class ActiveHashAdapter
2
- class << self
3
- def all(klass)
4
- klass.superclass.superclass.all
5
- end
6
-
7
- def delete_all
8
- @klass.superclass.delete_all
9
- end
10
-
11
- def exists?(id)
12
- @klass.find_by_id(id).present?
13
- end
14
-
15
- def where(*args)
16
- query = ActiveHash::SQLQueryExecutor.args_to_query(args)
17
- @klass.where(query)
18
- end
19
- end
20
- end