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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eef5378d8599dab8f59020a40480d00b017e32ec
4
- data.tar.gz: 3db390b3eec39ce26acd8d8294fab998531ac642
3
+ metadata.gz: 95f233eed5973387ebc3145d8dfca28c0e3f8abf
4
+ data.tar.gz: 0038db405a9efb385e5d0890a9fc9e24fbaddd89
5
5
  SHA512:
6
- metadata.gz: a08ec0f0849056f9499e8d982622ccadce3ddd51ad00a87a75e213eb7d0988f03bf809310a6aedd35b11a8ea5e62294c0192c95db89980b106fdd44cb1dcd454
7
- data.tar.gz: 4034aeab3c5a421997e82ea0e55031a1d24cfadab2a4cbb196d2c52d7b394b3fb4dfa13219518f2f41311496f451a1e6211edb05c111428a909c0a3f50c57203
6
+ metadata.gz: 2f55598f2da3aac54ed04c6e99b46eede83391ed45ff68acbe399c157e446102116ba8f574386c905667266d19deaa11dbfc00c95f1df273c4b282428d5dc09c
7
+ data.tar.gz: 8b77bb643d97a6abd61a1fa31960690a5677120611bebdf9bb00fee8cc391b92ad8700e82ca86b4756c7cc7add9651d93a6b558ac93fd67ef9ea77b19b6c7def
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Thorwald
2
- VERSION='0.1.1'
2
+ VERSION='0.2.0'
3
3
  end
@@ -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
- 3.times { Document.create }
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([Document.last.as_json])
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(Document.all.offset(1).limit(2).as_json)
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(Document.all.offset(1).limit(1).as_json)
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
@@ -12,6 +12,7 @@ SimpleCov.start 'gem'
12
12
 
13
13
  require 'pry-nav'
14
14
  require 'thorwald'
15
+ require 'timecop'
15
16
 
16
17
  require 'active_record'
17
18
  ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
@@ -2,6 +2,7 @@ ActiveRecord::Schema.define do
2
2
  self.verbose = false
3
3
 
4
4
  create_table :documents, :force => true do |t|
5
+ t.string :name
5
6
  t.timestamps null: true
6
7
  end
7
8
  end
@@ -28,4 +28,5 @@ Gem::Specification.new do |gem|
28
28
  gem.add_development_dependency 'pry-nav'
29
29
  gem.add_development_dependency 'simplecov'
30
30
  gem.add_development_dependency 'codeclimate-test-reporter'
31
+ gem.add_development_dependency 'timecop'
31
32
  end
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.1.1
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-21 00:00:00.000000000 Z
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