openstax_connect 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -35,25 +35,45 @@ There is also a logout path helper for `/connect/sessions/destroy`, given by `lo
35
35
 
36
36
  config.logout_via = :delete
37
37
 
38
- Make sure to install the engine's migrations:
38
+ OpenStax Connect provides you with an `OpenStax::Connect::User` object. You can
39
+ use this as your app's User object without modification, you can modify it to suit
40
+ your app's needs (not recommended), or you can provide your own custom User object
41
+ that references the OpenStax Connect User object.
39
42
 
40
- rake openstax_connect:install:migrations
43
+ OpenStax Connect also provides you methods for getting and setting the current
44
+ signed in user (`current_user` and `current_user=` methods). If you choose to create
45
+ your own custom User object that references the User object provide by Connect,
46
+ you can teach OpenStax Connect how to translate between your app's custom User
47
+ object and OpenStax Connect's built-in User object.
41
48
 
42
- You also need to create your own User and AnonymousUser models. Once you do this, include concerns from the connect gem to get their baseline functionality.
49
+ To do this, you need to set a `user_provider` in this configuration.
43
50
 
44
- class User < ActiveRecord::Base
45
- include OpenStax::Connect::Models::User
46
- ...
47
- end
51
+ config.user_provider = MyUserProvider
48
52
 
49
- and
53
+ The user_provider is a class that provides two class methods:
50
54
 
51
- class AnonymousUser < ActiveRecord::Base
52
- include OpenStax::Connect::Models::AnonymousUser
53
- ...
55
+ def self.connect_user_to_app_user(connect_user)
56
+ # converts the given connect user to an app user
57
+ # if you want to cache the connect_user in the app user
58
+ # this is the place to do it.
59
+ # If no app user exists for this connect user, one should
60
+ # be created.
54
61
  end
62
+
63
+ def self.app_user_to_connect_user(app_user)
64
+ # converts the given app user to a connect user
65
+ end
55
66
 
56
- Check out the engine code in app/concerns to see what this gets you.
67
+ Connect users are never nil. When a user is signed out, the current connect user
68
+ is an anonymous user (responding true to `is_anonymous?`). You can follow the same
69
+ pattern in your app or you can use nil for the current user. Just remember to check
70
+ the anonymous status of connect users when doing your connect <-> app translations.
71
+
72
+ The default `user_provider` just uses OpenStax::Connect::User as the app user.
73
+
74
+ Make sure to install the engine's migrations:
75
+
76
+ rake openstax_connect:install:migrations
57
77
 
58
78
  Example Application
59
79
  -------------------
@@ -1,30 +1,24 @@
1
1
  class ActionController::Base
2
2
 
3
- before_filter {
4
- @current_user_manager = OpenStax::Connect::CurrentUserManager.new(request,
5
- session,
6
- cookies)
7
- }
8
-
9
3
  # Returns the current app user
10
4
  def current_user
11
- @current_user_manager.current_user
5
+ current_user_manager.current_user
12
6
  end
13
7
 
14
8
  # Signs in the given user; the argument can be either a connect user or
15
9
  # an app user
16
10
  def sign_in(user)
17
- @current_user_manager.sign_in(user)
11
+ current_user_manager.sign_in(user)
18
12
  end
19
13
 
20
14
  # Signs out the current user
21
15
  def sign_out!
22
- @current_user_manager.sign_out!
16
+ current_user_manager.sign_out!
23
17
  end
24
18
 
25
19
  # Returns true iff there is a user signed in
26
20
  def signed_in?
27
- @current_user_manager.signed_in?
21
+ current_user_manager.signed_in?
28
22
  end
29
23
 
30
24
  # Useful in before_filters
@@ -38,5 +32,11 @@ protected
38
32
 
39
33
  helper_method :current_user, :signed_in?
40
34
 
35
+ def current_user_manager
36
+ @current_user_manager ||= OpenStax::Connect::CurrentUserManager.new(request,
37
+ session,
38
+ cookies)
39
+ end
40
+
41
41
  end
42
42
 
@@ -11,7 +11,7 @@ module OmniAuth
11
11
  :authorize_url => "/oauth/authorize"
12
12
  }
13
13
 
14
- uid { raw_info["uid"] }
14
+ uid { raw_info["id"] }
15
15
 
16
16
  info do
17
17
  {
@@ -23,7 +23,7 @@ module OmniAuth
23
23
  end
24
24
 
25
25
  def raw_info
26
- @raw_info ||= access_token.get('/api/v1/me.json').parsed
26
+ @raw_info ||= access_token.get('/api/users/me.json').parsed
27
27
  end
28
28
  end
29
29
  end
@@ -10,6 +10,11 @@ module OpenStax
10
10
  class Engine < ::Rails::Engine
11
11
  isolate_namespace OpenStax::Connect
12
12
 
13
+ initializer "openstax_connect.factories",
14
+ :after => "factory_girl.set_factory_paths" do
15
+ FactoryGirl.definition_file_paths << File.join(root, 'spec', 'factories') if defined?(FactoryGirl)
16
+ end
17
+
13
18
  config.autoload_paths << File.expand_path("../../../app/routines", __FILE__)
14
19
  config.autoload_paths << File.expand_path("../../../app/handlers", __FILE__)
15
20
  config.autoload_paths << File.expand_path("../../../app/concerns", __FILE__)
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Connect
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -47,41 +47,7 @@ module OpenStax
47
47
  attr_accessor :default_errors_added_trigger
48
48
  attr_accessor :security_transgression_exception
49
49
 
50
- # OpenStax Connect provides you with an OpenStax::Connect::User object. You can
51
- # use this as your app's User object without modification, you can modify it to suit
52
- # your app's needs (not recommended), or you can provide your own custom User object
53
- # that references the OpenStax Connect User object.
54
- #
55
- # OpenStax Connect also provides you methods for getting and setting the current
56
- # signed in user (current_user and current_user= methods). If you choose to create
57
- # your own custom User object that references the User object provide by Connect,
58
- # you can teach OpenStax Connect how to translate between your app's custom User
59
- # object and OpenStax Connect's built-in User object.
60
- #
61
- # To do this, you need to set a "user_provider" in this configuration.
62
- #
63
- # config.user_provider = MyUserProvider
64
- #
65
- # The user_provider is a class that provides two class methods:
66
- #
67
- # def self.connect_user_to_app_user(connect_user)
68
- # # converts the given connect user to an app user
69
- # # if you want to cache the connect_user in the app user
70
- # # this is the place to do it.
71
- # # If no app user exists for this connect user, one should
72
- # # be created.
73
- # end
74
- #
75
- # def self.app_user_to_connect_user(app_user)
76
- # # converts the given app user to a connect user
77
- # end
78
- #
79
- # Connect users are never nil. When a user is signed out, the current connect user
80
- # is an anonymous user (responding true is "is_anonymous?"). You can follow the same
81
- # pattern in your app or you can use nil for the current user. Just remember to check
82
- # the anonymous status of connect users when doing your connect <-> app translations.
83
- #
84
- # The default user_provider just uses OpenStax::Connect::User as the app user.
50
+ # See the "user_provider" discussion in the README
85
51
  attr_accessor :user_provider
86
52
 
87
53
  def openstax_services_url=(url)
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax::Connect
4
+ describe SessionsController do
5
+
6
+ describe "GET 'create'" do
7
+ it "returns http success" do
8
+ get 'create'
9
+ response.should be_success
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :openstax_connect_user, :class => OpenStax::Connect::User do
3
+ sequence(:username){ |n| "Application #{n}" }
4
+ sequence(:openstax_uid){ |n| n }
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the SessionsHelper. For example:
5
+ #
6
+ # describe SessionsHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ module OpenStax::Connect
14
+ describe SessionsHelper do
15
+ pending "add some examples to (or delete) #{__FILE__}"
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax::Connect
4
+ describe User do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ # ## Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+
28
+ # If true, the base class of anonymous controllers will be inferred
29
+ # automatically. This will be the default behavior in future versions of
30
+ # rspec-rails.
31
+ config.infer_base_class_for_anonymous_controllers = false
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = "random"
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-08 00:00:00.000000000 Z
12
+ date: 2014-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.13
21
+ version: 3.2.14
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.2.13
29
+ version: 3.2.14
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: omniauth
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +91,70 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 2.0.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: openstax_utilities
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.2.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.2.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: sass-rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 3.2.3
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 3.2.3
126
+ - !ruby/object:Gem::Dependency
127
+ name: coffee-rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 3.2.1
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 3.2.1
142
+ - !ruby/object:Gem::Dependency
143
+ name: uglifier
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.0.3
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 1.0.3
94
158
  - !ruby/object:Gem::Dependency
95
159
  name: sqlite3
96
160
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +187,54 @@ dependencies:
123
187
  - - ! '>='
124
188
  - !ruby/object:Gem::Version
125
189
  version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: factory_girl_rails
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ - !ruby/object:Gem::Dependency
207
+ name: quiet_assets
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: thin
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
126
238
  description: Rails common code and bindings and for 'services' API
127
239
  email:
128
240
  - jps@kindlinglabs.com
@@ -170,9 +282,14 @@ files:
170
282
  - lib/openstax/connect/version.rb
171
283
  - lib/openstax_connect.rb
172
284
  - lib/tasks/connect-rails_tasks.rake
285
+ - spec/factories/openstax_connect_user.rb
173
286
  - MIT-LICENSE
174
287
  - Rakefile
175
288
  - README.md
289
+ - spec/controllers/openstax/connect/sessions_controller_spec.rb
290
+ - spec/helpers/openstax/connect/sessions_helper_spec.rb
291
+ - spec/models/openstax/connect/user_spec.rb
292
+ - spec/spec_helper.rb
176
293
  homepage: http://github.com/openstax/connect-rails
177
294
  licenses: []
178
295
  post_install_message:
@@ -187,7 +304,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
304
  version: '0'
188
305
  segments:
189
306
  - 0
190
- hash: -4136033706291355193
307
+ hash: -3223969092906496929
191
308
  required_rubygems_version: !ruby/object:Gem::Requirement
192
309
  none: false
193
310
  requirements:
@@ -196,11 +313,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
313
  version: '0'
197
314
  segments:
198
315
  - 0
199
- hash: -4136033706291355193
316
+ hash: -3223969092906496929
200
317
  requirements: []
201
318
  rubyforge_project:
202
319
  rubygems_version: 1.8.25
203
320
  signing_key:
204
321
  specification_version: 3
205
322
  summary: Rails common code and bindings and for 'services' API
206
- test_files: []
323
+ test_files:
324
+ - spec/controllers/openstax/connect/sessions_controller_spec.rb
325
+ - spec/factories/openstax_connect_user.rb
326
+ - spec/helpers/openstax/connect/sessions_helper_spec.rb
327
+ - spec/models/openstax/connect/user_spec.rb
328
+ - spec/spec_helper.rb