mince 2.2.0 → 2.3.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 +4 -4
- data/lib/mince/data_model.rb +10 -1
- data/lib/mince/model/finders.rb +5 -0
- data/lib/mince/shared_examples/interface_example.rb +19 -11
- data/lib/mince/version.rb +1 -1
- data/spec/support/shared_examples/model_finders_example.rb +29 -1
- data/spec/units/mince/data_model_spec.rb +13 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ddaa9a9ed2495663343af3ef6e5e4b111b339a5
|
4
|
+
data.tar.gz: a37f65f96b0229e038cd83f4a2dc8a3b77fcda17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 762a3fd86f01138c9a5b423eb738021347171ac3a21a9947531e2aee04e4c4ebde19c3e362dd894e115b35853463cbe4ec19098cb058e96aa89f754d13fce1b4
|
7
|
+
data.tar.gz: dabf7116329ad47e90a056f8a15d8a0705558e1a2294f9a92e9b2ae7450e606e8edfae8c725483bd1647534106dfc7ffdb5bcf1e9fc2a62dc02ac759462ed96d
|
data/lib/mince/data_model.rb
CHANGED
@@ -190,7 +190,7 @@ module Mince # :nodoc:
|
|
190
190
|
translate_each_from_interface interface.get_all_for_key_with_value(data_collection, field, value)
|
191
191
|
end
|
192
192
|
|
193
|
-
# Finds all
|
193
|
+
# Finds all records that match a set of key / value pairs
|
194
194
|
#
|
195
195
|
# @param [Hash] hash a hash of field / value pairs to query records for
|
196
196
|
# @returns [Array] the set of records matching all key / value pairs
|
@@ -198,6 +198,15 @@ module Mince # :nodoc:
|
|
198
198
|
translate_each_from_interface interface.get_by_params(data_collection, hash)
|
199
199
|
end
|
200
200
|
|
201
|
+
# Finds all records that match a set of key / value pairs
|
202
|
+
#
|
203
|
+
# @param [Symbol] field the field to query for
|
204
|
+
# @param [*] Time object to find all records where field is less than value
|
205
|
+
# @returns [Array] the set of records matching all key / value pairs
|
206
|
+
def all_before(field, value)
|
207
|
+
translate_each_from_interface interface.all_before(data_collection, field, value)
|
208
|
+
end
|
209
|
+
|
201
210
|
# Finds One record that matches all of the field / value pairs
|
202
211
|
#
|
203
212
|
# @param [Hash] hash the hash to query for
|
data/lib/mince/model/finders.rb
CHANGED
@@ -48,6 +48,11 @@ module Mince
|
|
48
48
|
a = data_model.find(id)
|
49
49
|
new a if a
|
50
50
|
end
|
51
|
+
|
52
|
+
# Returns all models where the field has a value that is less than the given value
|
53
|
+
def all_before(field, value)
|
54
|
+
data_model.all_before(field, value).map{|a| new(a) }
|
55
|
+
end
|
51
56
|
end
|
52
57
|
end
|
53
58
|
end
|
@@ -2,10 +2,10 @@ require_relative '../../mince'
|
|
2
2
|
|
3
3
|
# = Shared example for a Mince Interface
|
4
4
|
#
|
5
|
-
# This is an Rspec Shared Example. It provides the ability to test
|
5
|
+
# This is an Rspec Shared Example. It provides the ability to test
|
6
6
|
# shared behavior of objects without duplication.
|
7
7
|
#
|
8
|
-
# Use this shared example as documentation on what API a mince data interface
|
8
|
+
# Use this shared example as documentation on what API a mince data interface
|
9
9
|
# must implement and as a specification and integration test while developing
|
10
10
|
# your mince data interface.
|
11
11
|
#
|
@@ -15,7 +15,7 @@ require_relative '../../mince'
|
|
15
15
|
# as a gem dependency in my library (in your Gemfile or gemspec file). I would
|
16
16
|
# add Rspec, create a new spec file at spec/integration/mince_interface_spec.rb
|
17
17
|
# with the following contents
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# require_relative '../../lib/my_mince_mysql'
|
20
20
|
# require 'mince/shared_examples/interface_example'
|
21
21
|
#
|
@@ -26,9 +26,9 @@ require_relative '../../mince'
|
|
26
26
|
#
|
27
27
|
# it_behaves_like 'a mince interface'
|
28
28
|
# end
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# Run your spec
|
31
|
-
#
|
31
|
+
#
|
32
32
|
# bundle exec spec rspec/integration/mince_inerface_spect.rb
|
33
33
|
#
|
34
34
|
# Make the failures pass, when there are no failures your interface is fully
|
@@ -42,9 +42,9 @@ shared_examples_for 'a mince interface' do
|
|
42
42
|
let(:interface) { Mince::Config.interface }
|
43
43
|
let(:primary_key) { interface.primary_key }
|
44
44
|
|
45
|
-
let(:data1) { { primary_key => 1, field_1: 'value 1', field_2: 3, field_3: [1, 2, 3], shared_between_1_and_2: 'awesome_value', :some_array => [1, 2, 3, 4]} }
|
46
|
-
let(:data2) { { primary_key => 2, field_1: 'value 1.2', field_2: 6, shared_between_1_and_2: 'awesome_value', :some_array => [4, 5, 6]} }
|
47
|
-
let(:data3) { { primary_key => 3, field_1: 'value 3', field_2: 9, shared_between_1_and_2: 'not the same as 1 and 2', :some_array => [1, 7]} }
|
45
|
+
let(:data1) { { primary_key => 1, field_1: 'value 1', field_2: 3, field_3: [1, 2, 3], shared_between_1_and_2: 'awesome_value', :some_array => [1, 2, 3, 4], created_at: (Time.now.utc - 500000) } }
|
46
|
+
let(:data2) { { primary_key => 2, field_1: 'value 1.2', field_2: 6, shared_between_1_and_2: 'awesome_value', :some_array => [4, 5, 6], created_at: (Time.now.utc - 1000) } }
|
47
|
+
let(:data3) { { primary_key => 3, field_1: 'value 3', field_2: 9, shared_between_1_and_2: 'not the same as 1 and 2', :some_array => [1, 7], created_at: (Time.now.utc - 50) } }
|
48
48
|
|
49
49
|
before do
|
50
50
|
interface.clear
|
@@ -57,7 +57,7 @@ shared_examples_for 'a mince interface' do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "Generating a primary key" do
|
60
|
-
subject do
|
60
|
+
subject do
|
61
61
|
(1..number_of_records).map do |salt|
|
62
62
|
interface.generate_unique_id(salt)
|
63
63
|
end
|
@@ -80,7 +80,7 @@ shared_examples_for 'a mince interface' do
|
|
80
80
|
|
81
81
|
it 'can delete a collection' do
|
82
82
|
interface.delete_collection(:some_collection)
|
83
|
-
|
83
|
+
|
84
84
|
interface.find_all(:some_collection).to_a.should == []
|
85
85
|
end
|
86
86
|
|
@@ -128,6 +128,10 @@ shared_examples_for 'a mince interface' do
|
|
128
128
|
convert_each(interface.get_all_for_key_with_value(:some_collection, :shared_between_1_and_2, 'awesome_value')).should == convert_each([data1, data2])
|
129
129
|
end
|
130
130
|
|
131
|
+
it 'can get all records for a field before a given time' do
|
132
|
+
convert_each(interface.all_before(:some_collection, :created_at, Time.now.utc - 500)).should == convert_each([data1, data2])
|
133
|
+
end
|
134
|
+
|
131
135
|
it 'can get all records where a value includes any of a set of values' do
|
132
136
|
interface.containing_any(:some_collection, :some_array, []).to_a.should == []
|
133
137
|
convert_each(interface.containing_any(:some_collection, :some_array, [7, 2, 3])).should == convert_each([data1, data3])
|
@@ -167,7 +171,11 @@ shared_examples_for 'a mince interface' do
|
|
167
171
|
end
|
168
172
|
|
169
173
|
def convert(hash)
|
170
|
-
HashWithIndifferentAccess.new(hash)
|
174
|
+
HashWithIndifferentAccess.new(hash).tap do |h|
|
175
|
+
if h[:created_at]
|
176
|
+
h[:created_at] = h[:created_at].to_s
|
177
|
+
end
|
178
|
+
end
|
171
179
|
end
|
172
180
|
|
173
181
|
def convert_each(ary)
|
data/lib/mince/version.rb
CHANGED
@@ -51,6 +51,34 @@ shared_examples_for 'a model using mince model finders' do
|
|
51
51
|
it { should == models }
|
52
52
|
end
|
53
53
|
|
54
|
+
describe 'finding all before a given time for a given field' do
|
55
|
+
subject { klass.all_before(field, time) }
|
56
|
+
|
57
|
+
let(:field) { mock }
|
58
|
+
let(:time) { mock }
|
59
|
+
|
60
|
+
before do
|
61
|
+
klass.data_model.stub(:all_before).with(field, time).and_return(data)
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when records exist' do
|
65
|
+
let(:data) { [mock] }
|
66
|
+
let(:model) { mock }
|
67
|
+
|
68
|
+
before do
|
69
|
+
klass.stub(:new).with(data.first).and_return(model)
|
70
|
+
end
|
71
|
+
|
72
|
+
it { should == [model] }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when a record does not exist' do
|
76
|
+
let(:data) { [] }
|
77
|
+
|
78
|
+
it { should be_empty }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
54
82
|
describe 'finding all by fields by a given hash' do
|
55
83
|
subject { klass.all_by_fields(hash) }
|
56
84
|
|
@@ -60,7 +88,7 @@ shared_examples_for 'a model using mince model finders' do
|
|
60
88
|
klass.data_model.stub(:all_by_fields).with(hash).and_return(data)
|
61
89
|
end
|
62
90
|
|
63
|
-
context 'when
|
91
|
+
context 'when records exist' do
|
64
92
|
let(:data) { [mock] }
|
65
93
|
let(:model) { mock }
|
66
94
|
|
@@ -237,6 +237,19 @@ describe Mince::DataModel, 'Class Methods' do
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
|
+
describe "getting all data models where the field contains a value before the given time" do
|
241
|
+
let(:data_model) { {primary_key => 'some id'} }
|
242
|
+
let(:expected_data_models) { [HashWithIndifferentAccess.new({:id => 'some id', primary_key => 'some id'})] }
|
243
|
+
let(:data_models) { [data_model] }
|
244
|
+
subject { described_class.all_before(:some_field, 'some time') }
|
245
|
+
|
246
|
+
it 'returns the stored data models' do
|
247
|
+
interface.should_receive(:all_before).with(collection_name, :some_field, 'some time').and_return(data_models)
|
248
|
+
|
249
|
+
subject.should == expected_data_models
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
240
253
|
describe "removing a value from an array for a data model" do
|
241
254
|
let(:data_model_id) { '1234567' }
|
242
255
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mince
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Simpson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -115,28 +115,28 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ~>
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '1.
|
118
|
+
version: '1.6'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '1.
|
125
|
+
version: '1.6'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: hashy_db
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '2.
|
132
|
+
version: '2.1'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - ~>
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: '2.
|
139
|
+
version: '2.1'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: rb-fsevent
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|