Ok, i've currently got all the specs running. This is basically what i
had to do:
- First of all i had to include the ApplicationControllerMethods into
application_controller.rb
require 'oauth/controllers/application_controller_methods'
include OAuth::Controllers::ApplicationControllerMethods
- Then i added fixtures for two users, aaron & quentin. I called it
users.yml and put it in spec/fixtures. Make sure they have "password"
as their password, or you have to change some of the specs.
- Then i ran rake:db migrate for development & test
- Since i use Devise, "before_filter login_required" in
OauthorizedController which resides in oauth_controller_spec.rb was
wrong. I changed it to "before_filter authenticate_user!". I'm a bit
unsure if this is right but it makes the specs pass. Also, if you use
something other than Devise, change the before_filer accordingly.
- Lot's of specs fail due to missing routes for the Oauthorized
controller (which is only for testing purposes and should not be
included in routes.rb). I'm sure there is a cleaner way but my
solution is to draw a new set of routes before the specs for that
controller is run. Something like:
before do
MyApp::Application.routes.draw do
get '/interactive', :to => "oauthorized#interactive"
# add all routes needed here
end
end
You also have to add an after hook to make sure the rest of your tests
pass.
after do
MyApp::Application.reload_routes!
end
- Then i had to add an authenticate mehod for the User class. It takes
two arguments, i'm using email & password. It hould return a user if
it passes and nil if not.
- This method is then also used in the authenticate_user method that i
uncommented in oauth_controller.rb
- In Devise the logged_in? method is called user_signed_in? so I
created an alias for logged_in? in application_controller.rb
- I then added some relationships in user.rb to match the new classes
created.
has_many :client_applications
has_many :tokens, :class_name => 'OauthToken'
- One route was missing in the generator so i added it to routes.rb
match '/invalidate', :to => 'oauth#invalidate', :as
=> :invalidate
Onwards to creating a test app!
Henrik