active_repository 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a89df3ab13ee205a992866a699afb7e193a41f14
4
- data.tar.gz: bf4a2f80ec2ea48b1a7c4cd89ad508094e106f2d
3
+ metadata.gz: e9ca952750bf1662400683fb0e3914c22951d50c
4
+ data.tar.gz: 076094f4e75ec626cd123e4595b382f2ffe648d8
5
5
  SHA512:
6
- metadata.gz: d8c9193d2972cbb45ec0077b531af46380a01872af9a53d5d8737e036b95f50c547ae5c66c66c4d65000cafc382d0840b45f466450b6936cc0b4280efa19ecb3
7
- data.tar.gz: 426eb5187ceaf45153858e1471a9b51abf29f45fc77e4d9a4bf48171339cd0800341c7e7d795739652742fdbf65ba7ac69678f91ff0ae56c7e1b5d24155f9370
6
+ metadata.gz: 104242bf4ac101b011cea78b38b5df354e3b894f52ed0cd3526a56cc3738613aff2edc88dd4e6cb0ba60442e44f28fcf408f6189565aa1a6c050db1507ec75be
7
+ data.tar.gz: d789d7b0745f60dc3b90a389d02be2ec757f521ac064cab0464f05aef27b76f19221ff24edc79f7b377c855d793cee2a2a56c823fd273892006b7536c8630cdb
@@ -77,6 +77,17 @@ class ActiveRepository::ResultSet
77
77
  ActiveRepository::ResultSet.new(@klass, query, @attributes)
78
78
  end
79
79
 
80
+ def update_all(attrs)
81
+ if @klass.repository?
82
+ @klass.where(@query).each do |record|
83
+ record.update_attributes(attrs)
84
+ end
85
+ else
86
+ query = SqlQueryExecutor::Base.new(@query)
87
+ PersistenceAdapter.where(@klass, query).update_all(attrs)
88
+ end
89
+ end
90
+
80
91
  private
81
92
  def convert_query(query)
82
93
  @query = SqlQueryExecutor::Query::Normalizers::QueryNormalizer.clean_query(query)
@@ -1,3 +1,3 @@
1
1
  module ActiveRepository
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -74,6 +74,7 @@ describe ActiveRepository, "Base" do
74
74
  it_behaves_like '.serialized_attributes'
75
75
  it_behaves_like '.update_attribute'
76
76
  it_behaves_like '.update_attributes'
77
+ it_behaves_like '.update_all'
77
78
  it_behaves_like '.all'
78
79
  it_behaves_like '.where'
79
80
  it_behaves_like '.exists?'
@@ -142,6 +143,7 @@ describe ActiveRepository, "Base" do
142
143
  it_behaves_like '.serialized_attributes'
143
144
  it_behaves_like '.update_attribute'
144
145
  it_behaves_like '.update_attributes'
146
+ it_behaves_like '.update_all'
145
147
  it_behaves_like '.all'
146
148
  it_behaves_like '.where'
147
149
  it_behaves_like '.exists?'
@@ -215,6 +217,7 @@ describe ActiveRepository, "Base" do
215
217
  it_behaves_like '.serialized_attributes'
216
218
  it_behaves_like '.update_attribute'
217
219
  it_behaves_like '.update_attributes'
220
+ it_behaves_like '.update_all'
218
221
  it_behaves_like '.all'
219
222
  it_behaves_like '.where'
220
223
  it_behaves_like '.exists?'
@@ -213,7 +213,7 @@ describe ActiveRepository::ResultSet, :result_set do
213
213
  end
214
214
 
215
215
  context 'when result_set is empty' do
216
- it 'returns nil' do
216
+ it 'returns an empty array' do
217
217
  expect(subject.where('').all).to be_empty
218
218
  end
219
219
  end
@@ -21,7 +21,7 @@ shared_examples ".update_attribute" do
21
21
  Country.first.name.should == "Italy"
22
22
  end
23
23
 
24
- it "updates records whit string keys" do
24
+ it "updates records with string keys" do
25
25
  id = Country.first.id
26
26
  country = Country.find(id)
27
27
  country.update_attribute('name', "Germany")
@@ -39,7 +39,7 @@ shared_examples ".update_attributes" do
39
39
  Country.first.name.should == "Italy"
40
40
  end
41
41
 
42
- it "updates records whit string keys" do
42
+ it "updates records with string keys" do
43
43
  id = Country.first.id
44
44
  country = Country.find(id)
45
45
  country.update_attributes('name' => "Germany")
@@ -48,6 +48,26 @@ shared_examples ".update_attributes" do
48
48
  end
49
49
  end
50
50
 
51
+ shared_examples ".update_all" do
52
+ it "updates records" do
53
+ country = Country.where(language: 'English')
54
+ country.update_all(name: "Italy")
55
+
56
+ italys = Country.where(name: 'Italy')
57
+
58
+ italys.count.should == 3
59
+ end
60
+
61
+ it "updates records with string keys" do
62
+ country = Country.where(language: 'English')
63
+ country.update_all('name' => "Germany")
64
+
65
+ germanys = Country.where(name: 'Germany')
66
+
67
+ germanys.count.should == 3
68
+ end
69
+ end
70
+
51
71
  shared_examples ".all" do
52
72
  it "returns an empty array if data is nil" do
53
73
  Country.delete_all
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_repository
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Torres
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_hash