thorwald 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/thorwald/exporter.rb +5 -1
- data/lib/thorwald/version.rb +1 -1
- data/spec/lib/thorwald/exporter_spec.rb +48 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/support/schema.rb +1 -0
- data/thorwald.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95f233eed5973387ebc3145d8dfca28c0e3f8abf
|
4
|
+
data.tar.gz: 0038db405a9efb385e5d0890a9fc9e24fbaddd89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f55598f2da3aac54ed04c6e99b46eede83391ed45ff68acbe399c157e446102116ba8f574386c905667266d19deaa11dbfc00c95f1df273c4b282428d5dc09c
|
7
|
+
data.tar.gz: 8b77bb643d97a6abd61a1fa31960690a5677120611bebdf9bb00fee8cc391b92ad8700e82ca86b4756c7cc7add9651d93a6b558ac93fd67ef9ea77b19b6c7def
|
data/lib/thorwald/exporter.rb
CHANGED
@@ -24,6 +24,10 @@ class Thorwald::Exporter
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
+
def attribute
|
28
|
+
params[:attribute] || @attribute
|
29
|
+
end
|
30
|
+
|
27
31
|
def scoped
|
28
32
|
@scoped ||= clazz.where(where, last_record_id).order(attribute)
|
29
33
|
end
|
@@ -33,7 +37,7 @@ class Thorwald::Exporter
|
|
33
37
|
end
|
34
38
|
|
35
39
|
def last_record_id
|
36
|
-
params[:last_record] || clazz.last.try(attribute)
|
40
|
+
params[:last_record] || clazz.order(attribute).last.try(attribute)
|
37
41
|
end
|
38
42
|
|
39
43
|
def count
|
data/lib/thorwald/version.rb
CHANGED
@@ -4,6 +4,12 @@ describe Thorwald::Exporter do
|
|
4
4
|
let(:subject) { described_class.new(Document, parameters, options) }
|
5
5
|
let(:options) { {} }
|
6
6
|
let(:parameters) { {} }
|
7
|
+
let(:documents) do
|
8
|
+
Timecop.freeze(2.days.ago) do
|
9
|
+
3.times { Document.create }
|
10
|
+
end
|
11
|
+
Document.all.order(:id)
|
12
|
+
end
|
7
13
|
|
8
14
|
before do
|
9
15
|
Document.delete_all
|
@@ -18,12 +24,12 @@ describe Thorwald::Exporter do
|
|
18
24
|
|
19
25
|
context 'when there are documents' do
|
20
26
|
before do
|
21
|
-
|
27
|
+
documents
|
22
28
|
end
|
23
29
|
|
24
30
|
context 'but no paramters where given' do
|
25
31
|
it 'returns only the last document' do
|
26
|
-
expect(subject.as_json).to eq([
|
32
|
+
expect(subject.as_json).to eq([documents.last.as_json])
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
@@ -31,14 +37,52 @@ describe Thorwald::Exporter do
|
|
31
37
|
let(:parameters) { { last_record: Document.first.id } }
|
32
38
|
|
33
39
|
it 'returns all documents but the first' do
|
34
|
-
expect(subject.as_json).to eq(
|
40
|
+
expect(subject.as_json).to eq(documents.offset(1).limit(2).as_json)
|
35
41
|
end
|
36
42
|
|
37
43
|
context 'and count is given' do
|
38
44
|
let(:parameters) { { last_record: Document.first.id, count: 1 } }
|
39
45
|
|
40
46
|
it 'returns a limited set' do
|
41
|
-
expect(subject.as_json).to eq(
|
47
|
+
expect(subject.as_json).to eq([documents.second.as_json])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when givin options for attribute fetch' do
|
53
|
+
let(:options) { { attribute: :updated_at } }
|
54
|
+
let(:second) { documents.second }
|
55
|
+
|
56
|
+
before do
|
57
|
+
second.update(name: :new_name)
|
58
|
+
second.reload
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the document updated' do
|
62
|
+
expect(subject.as_json).to eq([second.as_json])
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'wben passing another target time' do
|
66
|
+
let(:parameters) { { last_record: documents.third.updated_at.to_s} }
|
67
|
+
let(:third) { documents.third }
|
68
|
+
|
69
|
+
before do
|
70
|
+
second.update(name: :new_name)
|
71
|
+
third.update(name: :new_name)
|
72
|
+
second.reload
|
73
|
+
third.reload
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the document updated after the last one' do
|
77
|
+
expect(subject.as_json).to eq(documents.offset(1).as_json)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'wben passing another attribute' do
|
82
|
+
let(:parameters) { { last_record: documents.first.id, attribute: :id} }
|
83
|
+
|
84
|
+
it 'returns the document updated after the last one' do
|
85
|
+
expect(subject.as_json).to eq(documents.offset(1).as_json)
|
42
86
|
end
|
43
87
|
end
|
44
88
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/schema.rb
CHANGED
data/thorwald.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thorwald
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: safe_attribute_assignment
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: timecop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
description: Gem for quick data exposure
|
154
168
|
email:
|
155
169
|
- darthjee@gmail.com
|