disiid_user 4.0.1 → 4.0.2

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: aa044938972c66d9e4fa7c5f005b589fdedc8d5a
4
- data.tar.gz: 83f7a1427949832bd5b0caa9d813d8dc7d0a374b
3
+ metadata.gz: bbb68883236561190cd994567c2dc9bdd3770b9b
4
+ data.tar.gz: faf56b478b6a939acf2eac2999abdd275f93174c
5
5
  SHA512:
6
- metadata.gz: dbd2a1293b0f9c721f91d466a07195f1eae238b45ca84bf3882969e430c7c05ae817c62074e0e99c9f3b0dcc378632807615dc45c32591fb35f615a4450e7936
7
- data.tar.gz: bb62f8268cb8b65a80d5a8e3937f0047900fe651ad9a916b048b34b171fd59dbfc519e2510ea788b1783a53e302115b136ac10e15db02b10aa8bf7165a4d62c1
6
+ metadata.gz: 75613e9b4b2c5db2e716c04391a4f79c6b7a063a2b5fc0f273f1d473707f1a4b1e9e64a88f0dbf4b2cadacd0cc71c2c8f8f05078784a89cd1202ff51225c2a97
7
+ data.tar.gz: 1f4867c5c95d93379d03398578e1433b77f1727ece21db364124829a16eaf8d0c26866ce246f6c8800cb9f52a288cd31c10c7e3d02130227eaee7a6b33e68ed1
data/lib/disiid_user.rb CHANGED
@@ -67,7 +67,7 @@ module DisiidUser
67
67
  # Creates a new user if it doesn't exist locally but is present remotely using #build_from_identity method.
68
68
  # This method will throw ActiveRecord::RecordNotFound exception if persistance process didn't go well.
69
69
  def find_local_or_remote_by_uuid!(id)
70
- user = first(conditions: ['identity_url LIKE ?', "%#{id}"])
70
+ user = where('identity_url LIKE ?', "%#{id}").first
71
71
  if !user && DisiidUser::RemoteUser.exists?(id, params: {auth_token: DisiidUser::RemoteUser.auth_token})
72
72
  # DisiidUser::RemoteUser.site is a URI::HTTP object, not a string
73
73
  user_url = DisiidUser::RemoteUser.site.merge("#{DisiidUser::RemoteUser.collection_name}/#{id}").to_s
@@ -1,3 +1,3 @@
1
1
  module DisiidUser
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
@@ -71,14 +71,14 @@ describe DisiidUser do
71
71
 
72
72
  it { should respond_to :find_local_or_remote_by_uuid! }
73
73
  it "should look for a local user" do
74
- user.should_receive(:first).with(hash_including(conditions: ['identity_url LIKE ?', '%some-uuid'])).and_return(true)
74
+ expect(User).to receive(:where).and_return([@user])
75
75
  user.find_local_or_remote_by_uuid!('some-uuid')
76
76
  end
77
77
 
78
78
  context "when local user doesn't exist" do
79
79
  let(:new_user) { mock('new user', :save! => true) }
80
80
  before {
81
- user.stub(:first).and_return(nil)
81
+ user.stub(:where).and_return([])
82
82
  user.stub(:build_from_identity).and_return(new_user)
83
83
  }
84
84
 
@@ -127,7 +127,7 @@ describe DisiidUser do
127
127
 
128
128
  context "when local user exists" do
129
129
  let(:existing_user) { mock('existing user') }
130
- before { user.stub(:first).and_return(existing_user) }
130
+ before { user.stub(:where).and_return([existing_user]) }
131
131
 
132
132
  it "should not fetch from remote" do
133
133
  DisiidUser::RemoteUser.should_not_receive(:exists?)
data/spec/stub_user.rb CHANGED
@@ -23,13 +23,11 @@ class User
23
23
  def self.scope(*args); end
24
24
 
25
25
  include DisiidUser
26
-
27
26
  end
28
27
 
29
28
  class FakeResponse
30
29
  attr_accessor :body
31
30
  def initialize(body); @body = body; end
32
-
33
31
  end
34
32
 
35
33
  # Stub ActiveRecord so that it won't do real HTTP requests
@@ -37,28 +35,11 @@ module ActiveResource
37
35
  class Connection
38
36
  # taps into ActiveRecord to read data from stub files
39
37
  # instead of doing a real HTTP request
40
- ## def get(path, *args)
41
- # def get(path, headers = {})
42
- # read_from_file(path)
43
- # rescue; raise ActiveResource::ResourceNotFound; end
44
- #
45
- # # stubs PUT request so to not do it for real
46
- ## def put(path, payload, headers)
47
- # def put(path, body = '', headers = {})
48
- # read_from_file(path)
49
- # rescue; raise ActiveResource::ResourceNotFound; end
50
- #
51
- # def patch(path, body = '', headers = {})
52
- # read_from_file(path)
53
- # rescue; raise ActiveResource::ResourceNotFound; end
54
-
55
- # # taps into ActiveRecord to read data from stub files
56
- # # instead of doing a real HTTP request
57
38
  # def get(path, *args)
58
39
  # read_from_file(path)
59
40
  # rescue; raise ActiveResource::ResourceNotFound; end
60
- #
61
- # # stubs PUT request so to not do it for real
41
+
42
+ # stubs PUT request so to not do it for real
62
43
  # def put(path, payload, headers)
63
44
  # read_from_file(path)
64
45
  # rescue; raise ActiveResource::ResourceNotFound; end
@@ -66,28 +47,18 @@ module ActiveResource
66
47
  private
67
48
 
68
49
  def read_from_file(fake_url_path)
69
- # if matched = /users\.(xml|json)/.match(fake_url_path)
70
- # filename = "#{File.dirname(__FILE__)}/users.#{matched[1]}"
71
- # else
72
- # # /collection_name/uuid?query
73
- # record = /\/[^\/]+\/([^\/\?]+)/.match(fake_url_path)[1]
74
- # # record string includes .xml or .json too
75
- # filename = "#{File.dirname(__FILE__)}/#{record}".sub(/\?.*$/, '')
76
- # end
77
- # fake_url_path
78
- # /users.xml?uuid=XXX
79
- # /users.xml
80
- if fake_url_path.match("uuid=")
81
- name = fake_url_path.split("?uuid=")[1]
82
- ext = fake_url_path.split("?uuid=")[0].split(".")[1]
83
- filename = "#{File.dirname(__FILE__)}/#{name}.#{ext}"
50
+ if matched = /users\.(xml|json)/.match(fake_url_path)
51
+ filename = "#{File.dirname(__FILE__)}/users.#{matched[1]}"
84
52
  else
85
- filename = "#{File.dirname(__FILE__)}/#{fake_url_path.split("?")[0].sub(/^\//, '')}"
53
+ # /collection_name/uuid?query
54
+ record = /\/[^\/]+\/([^\/\?]+)/.match(fake_url_path)[1]
55
+ # record string includes .xml or .json too
56
+ filename = "#{File.dirname(__FILE__)}/#{record}".sub(/\?.*$/, '')
86
57
  end
87
58
  # format is either ActiveResource::Formats::XmlFormat or JsonFormat
88
59
  # 3.0.x defaults to XML, 3.1.x defaults to JSON
89
60
  data = open(filename).read
90
- { :body => /3\.1/.match(ActiveResource::VERSION::STRING) ? FakeResponse.new(data) : format.decode(data) }
61
+ /3\.1/.match(ActiveResource::VERSION::STRING) ? FakeResponse.new(data) : format.decode(data)
91
62
  end
92
63
  end
93
64
  end
@@ -103,4 +74,3 @@ module Rails
103
74
  def self.cache; StubCache; end
104
75
  end
105
76
 
106
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disiid_user
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Severina
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-09 00:00:00.000000000 Z
12
+ date: 2015-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec