record_collection 0.4.6 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d78564aff4c9d3493bf4e5c3cfe0adcd45dc1dd
4
- data.tar.gz: 9caf058b010b857cdc2130e78f104eac76a8bf43
3
+ metadata.gz: 1dfc73354ba9b9a8f5c890106e92e7929f95b702
4
+ data.tar.gz: 99cf631416ce9a8ec12b1959c785d29b3a1da010
5
5
  SHA512:
6
- metadata.gz: da13c3bd14acad5192abacdf8cfe328a95c09611e01a2811d615cf89d5c420c78ed63f00a4da523f5031ba1ce6c750ba8e17e5c8d37891f5fe6b90b902adecc7
7
- data.tar.gz: 330143a4fb2164d75ec1fad8f2d8292e213a418464ffd7991691ded829ae6630f3ba5476b6c80a982a91b6c9918ff981e3a8444f1551501c57a66b80dcdde818
6
+ metadata.gz: 0df9ecbe183b157a5cbba434d6303ff5b48367ca1fde5510e7cdbf7bd22f35c1bd00e195e70d8109b541c4af7f8fb0d3cba3f5bf466dad2859bbbfc4caa0bab6
7
+ data.tar.gz: 011cc7ee0db03df40241cbf96a46a9a053b33f8cc340b0c64ccbd421fb8c14f48cbf8864d5ee23799a9bf9e64e4b51c2393631e9500993289eccf2479bd5ad0e
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -41,11 +41,16 @@ module RecordCollection
41
41
  old_validates attr, options
42
42
  end
43
43
 
44
+ #FINDERS
44
45
  def find(ids)
45
46
  raise "Cannot call find on a collection object if there is no record_class defined" unless respond_to?(:record_class) && record_class
46
47
  new(ids.present? ? record_class.find(ids) : [])
47
48
  end
48
49
 
50
+ # Create a new collection with the scope set to the result of the query on the record_class
51
+ def where(*args)
52
+ new record_class.where(*args)
53
+ end
49
54
  end
50
55
 
51
56
  def initialize(collection = [], params = {})
@@ -115,5 +120,8 @@ module RecordCollection
115
120
  results.first
116
121
  end
117
122
 
123
+ def ids
124
+ @ids ||= map(&:id)
125
+ end
118
126
  end
119
127
  end
@@ -1,3 +1,3 @@
1
1
  module RecordCollection
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RecordCollection::Base do
4
+
5
+ describe '#ids' do
6
+ it 'returns the ids of the collection' do
7
+ employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
8
+ described_class.new([employee]).ids.should eq [employee.id]
9
+ end
10
+
11
+ it 'returns an empty array for an empty collection' do
12
+ described_class.new.ids.should be_empty
13
+ end
14
+ end
15
+ end
@@ -26,4 +26,11 @@ RSpec.describe Employee::Collection do
26
26
  end
27
27
  end
28
28
 
29
+ describe '.where' do
30
+ it "fills the collection with records coming from the query performed on the record_class" do
31
+ employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
32
+ employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
33
+ described_class.where(admin: false).ids.should eq [employee2.id]
34
+ end
35
+ end
29
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin ter Kuile
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -284,6 +284,7 @@ extensions: []
284
284
  extra_rdoc_files: []
285
285
  files:
286
286
  - ".gitignore"
287
+ - ".rspec"
287
288
  - ".travis.yml"
288
289
  - Gemfile
289
290
  - LICENSE.txt
@@ -307,6 +308,7 @@ files:
307
308
  - lib/record_collection/rails/routes.rb
308
309
  - lib/record_collection/version.rb
309
310
  - record_collection.gemspec
311
+ - spec/base/accessors_spec.rb
310
312
  - spec/base/after_record_update_spec.rb
311
313
  - spec/base/delegation_spec.rb
312
314
  - spec/base/finding_records_spec.rb
@@ -405,6 +407,7 @@ signing_key:
405
407
  specification_version: 4
406
408
  summary: Manage collections of records in Ruby on Rails
407
409
  test_files:
410
+ - spec/base/accessors_spec.rb
408
411
  - spec/base/after_record_update_spec.rb
409
412
  - spec/base/delegation_spec.rb
410
413
  - spec/base/finding_records_spec.rb