social_plus-web_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ require 'active_support/core_ext/hash/deep_merge'
2
+ require 'social_plus/web_api/user'
3
+ require 'support/macros/social_plus_macros'
4
+
5
+ describe SocialPlus::WebApi::User do
6
+ include SocialPlusMacros
7
+
8
+ describe '.authenticate' do
9
+ let(:api_client) { double(:api_client) }
10
+ let(:token) { '1234567812345678123456781234567812345678' }
11
+ let(:user) { double(:user) }
12
+
13
+ before :each do
14
+ allow(api_client).to receive(:execute).with('authenticated_user', token: token, add_profile: true).and_return(authenticated_user_api_result)
15
+ allow(api_client).to receive(:execute).with('providers_of_user', identifier: authenticated_user_api_result['user']['identifier']).and_return(providers_of_user_api_result)
16
+ allow(SocialPlus::WebApi::User).to receive(:new).with(social_plus_user_params).and_return(user)
17
+ end
18
+
19
+ it { expect(SocialPlus::WebApi::User.authenticate(api_client, token)).to eq(user) }
20
+ end
21
+
22
+ let(:social_plus_user) { SocialPlus::WebApi::User.send(:new, social_plus_user_params) }
23
+
24
+ let(:last_logged_in_provider) { social_plus_user.last_logged_in_provider }
25
+
26
+ shared_examples_for 'an User instance' do
27
+ describe '#identifier' do
28
+ it { expect(social_plus_user.identifier).to eq('12345abcde12345abcde12345abcde12345abcde') }
29
+ end
30
+
31
+ describe '#profile' do
32
+ it { expect(social_plus_user.profile).to be_an_instance_of(SocialPlus::WebApi::Profile) }
33
+ end
34
+
35
+ describe '#followers' do
36
+ it { expect(social_plus_user.followers).to eq(200) }
37
+ end
38
+ end
39
+
40
+ context 'logged in directly' do
41
+ it_behaves_like 'an User instance'
42
+
43
+ describe '#last_logged_in_provider' do
44
+ it { expect(last_logged_in_provider).to eq('feedforce') }
45
+
46
+ describe '#facebook?' do
47
+ it { expect(last_logged_in_provider.facebook?).to eq(false) }
48
+ end
49
+
50
+ describe '#twitter?' do
51
+ it { expect(last_logged_in_provider.twitter?).to eq(false) }
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'logged in via facebook' do
57
+ before do
58
+ social_plus_user_params.deep_merge!('user' => { 'last_logged_in_provider' => 'facebook' })
59
+ end
60
+
61
+ it_behaves_like 'an User instance'
62
+
63
+ describe '#last_logged_in_provider' do
64
+ it { expect(last_logged_in_provider).to eq('facebook') }
65
+
66
+ describe '#facebook?' do
67
+ it { expect(last_logged_in_provider.facebook?).to eq(true) }
68
+ end
69
+
70
+ describe '#twitter?' do
71
+ it { expect(last_logged_in_provider.twitter?).to eq(false) }
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'logged in via twitter' do
77
+ before do
78
+ social_plus_user_params.deep_merge!('user' => { 'last_logged_in_provider' => 'twitter' })
79
+ end
80
+
81
+ it_behaves_like 'an User instance'
82
+
83
+ describe '#last_logged_in_provider' do
84
+ it { expect(last_logged_in_provider).to eq('twitter') }
85
+
86
+ describe '#facebook?' do
87
+ it { expect(last_logged_in_provider.facebook?).to eq(false) }
88
+ end
89
+
90
+ describe '#twitter?' do
91
+ it { expect(last_logged_in_provider.twitter?).to eq(true) }
92
+ end
93
+ end
94
+ end
95
+
96
+ context %q|when 'user' is missing| do
97
+ before do
98
+ social_plus_user_params.except!('user')
99
+ end
100
+
101
+ it 'should raise error' do
102
+ expect { social_plus_user }.to raise_error(ArgumentError, %q|missing 'user'|)
103
+ end
104
+ end
105
+
106
+ context %q|when 'user/identifier' is missing| do
107
+ before do
108
+ social_plus_user_params['user'].except!('identifier')
109
+ end
110
+
111
+ it 'should raise error' do
112
+ expect { social_plus_user }.to raise_error(ArgumentError, %q|missing 'user/identifier'|)
113
+ end
114
+ end
115
+
116
+ describe '#followers' do
117
+ context %q|when 'follow' is missing| do
118
+ before do
119
+ social_plus_user_params.except!('follow')
120
+ end
121
+
122
+ it { expect(social_plus_user.followers).to eq(0) }
123
+ end
124
+
125
+ context %q|when 'follow/followed_by' is missing| do
126
+ before do
127
+ social_plus_user_params['follow'].except!('followed_by')
128
+ end
129
+
130
+ it { expect(social_plus_user.followers).to eq(0) }
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ expectations.syntax = %I(expect)
5
+ end
6
+
7
+ # rspec-mocks config goes here. You can use an alternate test double
8
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ mocks.syntax = %I(expect)
12
+ end
13
+ end
@@ -0,0 +1,71 @@
1
+ require 'active_support/concern'
2
+
3
+ # :nodoc:
4
+ module SocialPlusMacros
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ let(:authenticated_user_api_result) {
9
+ {
10
+ 'user' => {
11
+ 'identifier' => '12345abcde12345abcde12345abcde12345abcde',
12
+ # primary_key
13
+ # mapped_at
14
+ # last_logged_in_at
15
+ 'last_logged_in_provider' => 'feedforce',
16
+ # login_count
17
+ # created_at
18
+ },
19
+ 'profile' => {
20
+ 'first_name' => 'Taro',
21
+ 'first_name_kana' => 'タロウ',
22
+ 'first_name_kanji' => '太郎',
23
+ # middle_ame
24
+ 'last_name' => 'YAMADA',
25
+ 'last_name_kana' => 'ヤマダ',
26
+ 'last_name_kanji' => '山田',
27
+ 'full_name' => 'YAMADA Taro',
28
+ 'full_name_kana' => 'ヤマダ タロウ',
29
+ 'full_name_kanji' => '山田 太郎',
30
+ 'user_name' => 'taro',
31
+ # verified
32
+ 'gender' => 1,
33
+ # blood_type
34
+ 'birthday' => '1990-01-01',
35
+ # relationship_status
36
+ 'location' => '東京都文京区1-2-1',
37
+ # location_id
38
+ 'location_jis_id' => 13106,
39
+ 'postal_code' => '112-0002',
40
+ # hometown
41
+ # hometown_id
42
+ # hometown_jis_id
43
+ # graduated_school
44
+ # graduated_school_type
45
+ # job_company
46
+ # job_position
47
+ 'uri' => %w(http://example.com),
48
+ # website
49
+ # quotes
50
+ # bio
51
+ # image_url
52
+ # last_updated_at
53
+ },
54
+ 'follow' => {
55
+ 'following' => 100,
56
+ 'followed_by' => 200
57
+ },
58
+ 'email' => [
59
+ { 'email' => 'taro-facebook@example.com', 'verified' => true, 'media_id' => 'facebook' },
60
+ { 'email' => 'taro-twitter@example.com', 'verified' => true, 'media_id' => 'twitter' }
61
+ ]
62
+ }
63
+ }
64
+ let(:providers_of_user_api_result) {
65
+ { 'providers' => %w(facebook twitter) }
66
+ }
67
+ let(:social_plus_user_params) {
68
+ authenticated_user_api_result.merge(providers_of_user_api_result)
69
+ }
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social_plus-web_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - OZAWA Sakuro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: This gem provides fundamental access to Social Plus's Web API.
112
+ email: sakuro+rubygems.org@2238club.org
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".rubocop.yml"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - lib/social_plus/web_api.rb
126
+ - lib/social_plus/web_api/api_error.rb
127
+ - lib/social_plus/web_api/client.rb
128
+ - lib/social_plus/web_api/http_response_error.rb
129
+ - lib/social_plus/web_api/invalid_token.rb
130
+ - lib/social_plus/web_api/prefectures.rb
131
+ - lib/social_plus/web_api/profile.rb
132
+ - lib/social_plus/web_api/user.rb
133
+ - lib/social_plus/web_api/version.rb
134
+ - lib/tasks/rspec.rake
135
+ - lib/tasks/rubocp.rake
136
+ - lib/tasks/yard.rake
137
+ - social_plus-web_api.gemspec
138
+ - spec/social_plus/web_api/client_spec.rb
139
+ - spec/social_plus/web_api/profile_spec.rb
140
+ - spec/social_plus/web_api/user_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/support/macros/social_plus_macros.rb
143
+ homepage: https://socialplus.jp
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '2.1'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.6.11
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: SocialPlus Web API client
167
+ test_files:
168
+ - spec/social_plus/web_api/client_spec.rb
169
+ - spec/social_plus/web_api/profile_spec.rb
170
+ - spec/social_plus/web_api/user_spec.rb
171
+ - spec/spec_helper.rb
172
+ - spec/support/macros/social_plus_macros.rb