socialmux 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +9 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +220 -0
  7. data/Rakefile +1 -0
  8. data/lib/socialmux/auth_mapper/base.rb +25 -0
  9. data/lib/socialmux/auth_mapper/facebook.rb +7 -0
  10. data/lib/socialmux/auth_mapper/github.rb +7 -0
  11. data/lib/socialmux/auth_mapper/google_oauth2.rb +7 -0
  12. data/lib/socialmux/auth_mapper/guess_name.rb +22 -0
  13. data/lib/socialmux/auth_mapper/linkedin.rb +7 -0
  14. data/lib/socialmux/auth_mapper/twitter.rb +7 -0
  15. data/lib/socialmux/auth_mapper.rb +26 -0
  16. data/lib/socialmux/event.rb +13 -0
  17. data/lib/socialmux/result.rb +15 -0
  18. data/lib/socialmux/strategy.rb +69 -0
  19. data/lib/socialmux/version.rb +4 -0
  20. data/lib/socialmux.rb +9 -0
  21. data/socialmux.gemspec +31 -0
  22. data/spec/fixtures/facebook_response.json +158 -0
  23. data/spec/fixtures/github_response.json +65 -0
  24. data/spec/fixtures/google_response.json +35 -0
  25. data/spec/fixtures/linkedin_response.json +45 -0
  26. data/spec/fixtures/twitter_response.json +239 -0
  27. data/spec/lib/.gitkeep +0 -0
  28. data/spec/lib/auth_mapper/facebook_spec.rb +18 -0
  29. data/spec/lib/auth_mapper/github_spec.rb +18 -0
  30. data/spec/lib/auth_mapper/google_oauth2_spec.rb +19 -0
  31. data/spec/lib/auth_mapper/linkedin_spec.rb +20 -0
  32. data/spec/lib/auth_mapper/twitter_spec.rb +22 -0
  33. data/spec/lib/result_spec.rb +17 -0
  34. data/spec/lib/strategy_spec.rb +112 -0
  35. data/spec/spec_helper.rb +12 -0
  36. data/spec/support/fixture_helpers.rb +13 -0
  37. data/spec/support/rspec_config.rb +11 -0
  38. metadata +210 -0
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ module Socialmux
4
+ describe Strategy do
5
+ let(:current_user) { nil }
6
+ let(:adapter) { stub('SchemaAdapter') }
7
+ let(:user) { stub('User') }
8
+ let(:mapper) { stub('Social::AuthMapper::Base', email: 'email') }
9
+ let(:omniauth_data) { stub('OmniAuth::AuthResult') }
10
+ let(:user_params) { stub('params') }
11
+
12
+ let(:strategy) do
13
+ Strategy.new(
14
+ current_user: current_user,
15
+ adapter: adapter,
16
+ omniauth_data: omniauth_data,
17
+ user_params: user_params
18
+ )
19
+ end
20
+ subject { strategy }
21
+
22
+ before do
23
+ strategy.stubs(:data).returns(mapper)
24
+ end
25
+
26
+ describe ".result" do
27
+ subject { strategy.result }
28
+
29
+ before do
30
+ strategy.stubs(:augment_user)
31
+ end
32
+
33
+ context "previous authentication is found" do
34
+ before do
35
+ adapter.stubs(:find_user_with_authentication).with(mapper).returns(user)
36
+ end
37
+
38
+ its(:user) { should eq user }
39
+ its(:event) { should eq Event::SIGN_IN }
40
+ end
41
+
42
+ context "current_user is present" do
43
+ let(:current_user) { user }
44
+
45
+ before do
46
+ adapter.stubs(:find_user_with_authentication).returns(nil)
47
+ strategy.result
48
+ end
49
+
50
+ its(:user) { should eq user }
51
+ its(:event) { should eq Event::TOUCHED_CURRENT_USER }
52
+
53
+ it "should augment the current user" do
54
+ expect(strategy).to have_received(:augment_user).with(user)
55
+ end
56
+ end
57
+
58
+ context "user with same email is present" do
59
+ before do
60
+ adapter.stubs(:find_user_with_authentication).returns(nil)
61
+ adapter.stubs(:find_user_with_email).with("email").returns(user)
62
+ strategy.result
63
+ end
64
+
65
+ its(:user) { should eq user }
66
+ its(:event) { should eq Event::TOUCHED_EMAIL_USER }
67
+
68
+ it "should augment the found user" do
69
+ expect(strategy).to have_received(:augment_user).with(user)
70
+ end
71
+ end
72
+
73
+ context "none of the above" do
74
+ before do
75
+ adapter.stubs(:init_user).returns(user)
76
+ adapter.stubs(:find_user_with_authentication).returns(nil)
77
+ adapter.stubs(:find_user_with_email).returns(nil)
78
+ strategy.result
79
+ end
80
+
81
+ its(:user) { should eq user }
82
+ its(:event) { should eq Event::SIGN_UP }
83
+
84
+ it "should augment the newly created user" do
85
+ expect(strategy).to have_received(:augment_user).with(user)
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "augment_user" do
91
+ before do
92
+ adapter.stubs(:update_user_with_data_if_blank)
93
+ adapter.stubs(:update_user_with_params)
94
+ adapter.stubs(:build_authentication)
95
+ strategy.send(:augment_user, user)
96
+ end
97
+
98
+ it "should call update_user_with_data_if_blank on the scheme adapter" do
99
+ expect(adapter).to have_received(:update_user_with_data_if_blank).with(user, mapper)
100
+ end
101
+
102
+ it "should call update_user_with_params on the scheme adapter" do
103
+ expect(adapter).to have_received(:update_user_with_params).with(user, user_params)
104
+ end
105
+
106
+ it "should call build_authentication on the scheme adapter" do
107
+ expect(adapter).to have_received(:build_authentication).with(user, mapper)
108
+ end
109
+ end
110
+ end
111
+ end
112
+
@@ -0,0 +1,12 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ require 'socialmux'
7
+
8
+ # add project root to load path
9
+ ROOT = File.expand_path('../..', __FILE__)
10
+ require File.join(ROOT, "spec/support/rspec_config.rb")
11
+ require File.join(ROOT, "spec/support/fixture_helpers.rb")
12
+
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+
3
+ module FixtureHelpers
4
+ def read_json(name)
5
+ fixture_path = File.join(ROOT, "spec/fixtures", "#{name}.json")
6
+ JSON.parse File.new(fixture_path).read
7
+ end
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+ config.include FixtureHelpers
12
+ end
13
+
@@ -0,0 +1,11 @@
1
+ require 'bourne'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = :expect
6
+ end
7
+ config.mock_with :mocha
8
+ config.order = "random"
9
+ config.fail_fast = true
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socialmux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefano Verna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-01 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
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: bourne
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: rspec
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: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashie
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Socialmux implements a strategy to add multiple social providers to the
126
+ same user. It's meant to be used togheter with OmniAuth.
127
+ email:
128
+ - stefano.verna@welaika.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - lib/socialmux.rb
140
+ - lib/socialmux/auth_mapper.rb
141
+ - lib/socialmux/auth_mapper/base.rb
142
+ - lib/socialmux/auth_mapper/facebook.rb
143
+ - lib/socialmux/auth_mapper/github.rb
144
+ - lib/socialmux/auth_mapper/google_oauth2.rb
145
+ - lib/socialmux/auth_mapper/guess_name.rb
146
+ - lib/socialmux/auth_mapper/linkedin.rb
147
+ - lib/socialmux/auth_mapper/twitter.rb
148
+ - lib/socialmux/event.rb
149
+ - lib/socialmux/result.rb
150
+ - lib/socialmux/strategy.rb
151
+ - lib/socialmux/version.rb
152
+ - socialmux.gemspec
153
+ - spec/fixtures/facebook_response.json
154
+ - spec/fixtures/github_response.json
155
+ - spec/fixtures/google_response.json
156
+ - spec/fixtures/linkedin_response.json
157
+ - spec/fixtures/twitter_response.json
158
+ - spec/lib/.gitkeep
159
+ - spec/lib/auth_mapper/facebook_spec.rb
160
+ - spec/lib/auth_mapper/github_spec.rb
161
+ - spec/lib/auth_mapper/google_oauth2_spec.rb
162
+ - spec/lib/auth_mapper/linkedin_spec.rb
163
+ - spec/lib/auth_mapper/twitter_spec.rb
164
+ - spec/lib/result_spec.rb
165
+ - spec/lib/strategy_spec.rb
166
+ - spec/spec_helper.rb
167
+ - spec/support/fixture_helpers.rb
168
+ - spec/support/rspec_config.rb
169
+ homepage: ''
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.0.0
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Socialmux implements a strategy to add multiple social providers to the same
193
+ user. It's meant to be used togheter with OmniAuth.
194
+ test_files:
195
+ - spec/fixtures/facebook_response.json
196
+ - spec/fixtures/github_response.json
197
+ - spec/fixtures/google_response.json
198
+ - spec/fixtures/linkedin_response.json
199
+ - spec/fixtures/twitter_response.json
200
+ - spec/lib/.gitkeep
201
+ - spec/lib/auth_mapper/facebook_spec.rb
202
+ - spec/lib/auth_mapper/github_spec.rb
203
+ - spec/lib/auth_mapper/google_oauth2_spec.rb
204
+ - spec/lib/auth_mapper/linkedin_spec.rb
205
+ - spec/lib/auth_mapper/twitter_spec.rb
206
+ - spec/lib/result_spec.rb
207
+ - spec/lib/strategy_spec.rb
208
+ - spec/spec_helper.rb
209
+ - spec/support/fixture_helpers.rb
210
+ - spec/support/rspec_config.rb