g5_updatable 0.5.0 → 0.5.1

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: 3da77bb3b76b2b886e1bbbbca5150cdc8335d2d3
4
- data.tar.gz: 650fa27e5eb4bb1c47198c4ffb8872d19a73d24e
3
+ metadata.gz: 6e5c5697b79384b5cc532c8a9d692f15784475fb
4
+ data.tar.gz: 7b862cf10c89e412bbb68d42004934539b5aaecc
5
5
  SHA512:
6
- metadata.gz: 4e6833532814f8e51d4cf898659e8f55051fa6939b1b39f57eca409d422654e91858db1f7a2c5d6ae2bbdbf12b5a3684f5b8924bea150b13bde7bfa912ff3734
7
- data.tar.gz: a68b14ed307b852fbdeccd95016055c6daa112927ddc4beef94cf4d17e43ec383a93e069b8ea21148a1100d52ef7366663d0cf28e7a01d4d6d6f6ae4fe772b7e
6
+ metadata.gz: 968edabc4d300e1fa34c6d56448ab37e28e64f1fccc08304899db06f1c30b19ef34910f63a9a9fd4ba3fb781a6da2eaaad530ce1fc058d4714279748ae13f54c
7
+ data.tar.gz: a29f3772392f43e9492cda4f923a2e6ca097c99216f7084c186bf546b4b9fddf919e5a95a124f8708a415e5e6a39b0926aca1d23cf5595377562f450cadaa5aa
@@ -1,12 +1,18 @@
1
1
  class G5Updatable::SyncsController < G5Updatable::BaseUpdatableController
2
2
 
3
+ before_filter :set_client
4
+
3
5
  def index
4
- timestamp = G5Updatable::Location.maximum(:updated_at)
6
+ timestamp = @client.locations.max_updated_at
5
7
  render json: {updated_at: formatted_timestamp(timestamp)}
6
8
  end
7
9
 
8
10
  private
9
11
 
12
+ def set_client
13
+ @client = G5Updatable::Client.find_by_urn!(params[:urn])
14
+ end
15
+
10
16
  def formatted_timestamp(timestamp)
11
17
  timestamp.in_time_zone.strftime("%I:%M%P on %B %e, %Y") if timestamp
12
18
  end
@@ -10,6 +10,5 @@ module G5Updatable
10
10
  })
11
11
 
12
12
  validates :uid, :urn, presence: true
13
-
14
13
  end
15
14
  end
@@ -6,5 +6,8 @@ module G5Updatable
6
6
 
7
7
  validates :uid, :urn, :client_uid, presence: true
8
8
 
9
+ scope :by_client_uid, -> (client_uid) { where(client_uid: client_uid) }
10
+ scope :max_updated_at, -> { maximum(:updated_at) }
11
+
9
12
  end
10
13
  end
@@ -6,14 +6,14 @@ class G5Updatable::LocationsUpdater
6
6
  def update
7
7
  @g5_locations.each do |g5_location|
8
8
  attributes = g5_location.location_hash.dup
9
-
10
9
  G5Updatable::Location.
11
10
  find_or_initialize_by(uid: attributes[:uid]).
12
11
  update_attributes!(
13
12
  urn: attributes[:urn],
14
13
  name: attributes[:name],
15
14
  client_uid: attributes[:client_uid],
16
- properties: attributes
15
+ properties: attributes,
16
+ updated_at: DateTime.now
17
17
  )
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module G5Updatable
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -4,17 +4,27 @@ describe G5Updatable::SyncsController, type: :controller do
4
4
  routes { G5Updatable::Engine.routes }
5
5
 
6
6
  describe 'GET index' do
7
- let!(:location) { create(:location) }
8
- let!(:location2) { create(:location) }
7
+ let(:client){ create(:client) }
8
+ let!(:location) { create(:location, client: client) }
9
+ let!(:location2) { create(:location, client: client) }
10
+ let!(:location3) { create(:location, client: create(:client)) }
9
11
  let(:expected_result) { location2.updated_at.in_time_zone.strftime("%I:%M%P on %B %e, %Y") }
12
+ let(:params) { {urn: client.urn } }
10
13
 
11
- before do
12
- get :index
13
- @result = JSON.parse response.body
14
+ subject do
15
+ get :index, params
16
+ JSON.parse response.body
14
17
  end
15
18
 
16
- it 'serializes' do
17
- expect(@result['updated_at']).to eq(expected_result)
18
- end
19
+ its(['updated_at']){ should eq(expected_result) }
20
+
21
+ describe "no client" do
22
+ let(:params) { {urn: "xxx" } }
23
+
24
+ it "raises" do
25
+ # This error will cause rails to return a 404 in production
26
+ expect{ subject }.to raise_error(ActiveRecord::RecordNotFound)
27
+ end
28
+ end
19
29
  end
20
30
  end