Skip to content

Commit

Permalink
Switched from fakeweb to webmock to work with the Rack::OAuth2 http c…
Browse files Browse the repository at this point in the history
…lient. Fixed code and have tests passing now.
  • Loading branch information
eedrummer committed Aug 28, 2012
1 parent a118fb4 commit a95589d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ group :test do
gem 'feedzirra'
gem 'cover_me'
gem 'factory_girl_rails'
gem 'fakeweb'
gem 'webmock'
end
9 changes: 6 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ GEM
cover_me (1.2.0)
configatron
hashie
crack (0.3.1)
curb (0.8.1)
daemons (1.1.9)
devise (2.1.2)
Expand All @@ -94,15 +95,14 @@ GEM
warden (~> 1.2.1)
erubis (2.7.0)
eventmachine (0.12.10)
excon (0.16.1)
excon (0.16.2)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (4.0.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.0.0)
factory_girl (~> 4.0.0)
railties (>= 3.0.0)
fakeweb (1.3.0)
feedzirra (0.0.24)
activesupport (>= 2.3.8)
builder (>= 2.1.2)
Expand Down Expand Up @@ -249,6 +249,9 @@ GEM
macaddr (~> 1.0)
warden (1.2.1)
rack (>= 1.0)
webmock (1.8.9)
addressable (>= 2.2.7)
crack (>= 0.1.7)
yamler (0.1.0)

PLATFORMS
Expand All @@ -262,7 +265,6 @@ DEPENDENCIES
devise
devise_oauth2_providable!
factory_girl_rails
fakeweb
feedzirra
health-data-standards!
heroku
Expand All @@ -283,3 +285,4 @@ DEPENDENCIES
thin
turn
uglifier (>= 1.0.3)
webmock
4 changes: 3 additions & 1 deletion app/controllers/vital_sign_callback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def access_code
vsa = current_user.vital_sign_auths.where(access_token: nil).first
access_token = vsa.vital_sign_feed.obtain_access_token(params[:code], url_for(controller: 'vital_sign_callback',
action: 'access_code'))
vsa.access_token = access_token.to_s

vsa.access_token = access_token.access_token
vsa.refresh_token = access_token.refresh_token
vsa.save!

#TODO: fetch the new vital signs
Expand Down
1 change: 1 addition & 0 deletions app/models/vital_sign_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class VitalSignAuth
embedded_in :user

field :access_token, type: String
field :refresh_token, type: String

belongs_to :vital_sign_feed
end
4 changes: 2 additions & 2 deletions test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@

factory :vital_sign_feed do
url 'http://foo.bar.com/vs1'
vital_sign_host {FactoryGirl.build :vital_sign_host}
record {FactoryGirl.build :record}
vital_sign_host
record
end

end
10 changes: 5 additions & 5 deletions test/functional/vital_sign_callback_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class VitalSignCallbackControllerTest < ActionController::TestCase

test "should get access_code" do
@user.vital_sign_auths << VitalSignAuth.new(vital_sign_feed: @vital_sign_feed)
FakeWeb.register_uri(:get, "http://#{@vital_sign_feed.vital_sign_host.hostname}/authorize",
:body => '{
stub_request(:post, "https://#{@vital_sign_feed.vital_sign_host.hostname}/oauth2/token")
.to_return(:body => '{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"token_type":"bearer",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter":"example_value"
}')
get :access_code
}', :status => 200)
get :access_code, code: 'sekret'
assert_response :redirect
@user.reload
assert_equal "2YotnFZFEjr1zCsicMWpAA", @user.vital_sign_auths.first.access_token
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'cover_me'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'webmock/test_unit'

class ActiveSupport::TestCase

Expand Down

0 comments on commit a95589d

Please sign in to comment.