Skip to content

Commit

Permalink
authenticating users in the controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rdingwell committed Feb 7, 2012
1 parent 783fd94 commit bba8f19
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'ruby-openid', :git => 'https://github.com/rdingwell/ruby-openid.git',:branc
gem "mongoid"
gem "bson_ext"
gem "pry"
gem 'pry-nav'
gem "capistrano"
gem 'heroku'
gem "nokogiri"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.7)
slop (>= 2.4.3, < 3)
pry-nav (0.1.0)
pry (~> 0.9.8.1)
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
Expand Down Expand Up @@ -244,6 +246,7 @@ DEPENDENCIES
omniauth
omniauth-openid
pry
pry-nav
rails (= 3.2.1)
ruby-openid!
sass-rails (~> 3.2.3)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery

#before_filter :authenticate_user!
before_filter :authenticate_user!
before_filter :find_record, :audit_log
private

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/authentications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def index
def create

omniauth = request.env["omniauth.auth"]
puts omniauth.inspect
authentication = Authentication.first(conditions: { provider: omniauth['provider'], uid: omniauth['uid']})
binding.pry
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
Expand All @@ -21,6 +21,7 @@ def create
user = User.new
user.apply_omniauth(omniauth)
if user.save
user.authentications[0].save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ def password_required?
end


def username
email
end


end
11 changes: 10 additions & 1 deletion test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
gender 'M'
sequence(:medical_record_number) {|n| n}
end
end


factory :user do |u|
u.sequence(:email) { |n| "testuser#{n}@test.com"}
u.password 'password'
u.password_confirmation 'password'
u.sequence(:name) { |n| "testuser#{n}"}
end

end
6 changes: 5 additions & 1 deletion test/functional/audit_logs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
include Devise::TestHelpers

class AuditLogsControllerTest < ActionController::TestCase

include Devise::TestHelpers
setup do
@request.env["devise.mapping"] = Devise.mappings
@user = FactoryGirl.create(:user)
sign_in @user
## clean out auditlog table
AuditLog.all.each {|x| x.destroy}
end

test "audit log GET 'index'" do

get :index
assert_response :success
end
Expand Down
5 changes: 5 additions & 0 deletions test/functional/c32_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'test_helper'

class C32ControllerTest < ActionController::TestCase
include Devise::TestHelpers

setup do
records = FactoryGirl.create_list(:record, 25)
@record = records.first
@request.env["devise.mapping"] = Devise.mappings
@user = FactoryGirl.create(:user)
sign_in @user

end

test "get c32 as xml" do
Expand Down
4 changes: 4 additions & 0 deletions test/functional/results_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
require "json"

class ResultsControllerTest < ActionController::TestCase
include Devise::TestHelpers

# Called before every test method runs. Can be used
# to set up fixture information.
def setup
@request.env["devise.mapping"] = Devise.mappings
@user = FactoryGirl.create(:user)
sign_in @user
# Create a bare record to work with, just borrowed data record from fixtures
data = JSON.parse('{ "_id" : "4e57b6c04f85cffb1d000001", "first" : "Rhonda", "medical_record_number" : "1", "patient_id" : "5838337972", "last" : "Sparks", "gender" : "F", "birthdate" : -790874989, "addresses" : [ { "street" : [ "26 Park Street" ], "city" : "Burlington", "state" : "VT", "postalCode" : "05400" } ], "measures" : {}, "encounters" : [ { "codes" : { "CPT" : [ "99201" ] }, "time" : 1265256841, "description" : "Outpatient encounter" }, { "codes" : { "CPT" : [ "99201" ] }, "time" : 1287994563, "description" : "Outpatient encounter" }, { "codes" : { "CPT" : [ "99385" ] }, "time" : 1277523855, "description" : "Preventative encounter" } ], "conditions" : [ { "codes" : { "ICD-9-CM" : [ "401.0" ] }, "time" : 1266487005, "description" : "Hypertension" }, { "codes" : { "SNOMED-CT" : [ "105539002" ] }, "time" : 1267924277, "description" : "Tobacco Non-user" } ], "results" : [ { "codes" : { "SNOMED-CT" : [ "439958008" ] }, "time" : 1265256841, "description" : "Cervical cancer screening" } ], "vital_signs" : [ { "codes" : { "SNOMED-CT" : [ "12929001" ] }, "value" : { "scalar" : 146, "units" : "mmHg" }, "time" : 1287994563, "description" : "Systolic" }, { "codes" : { "SNOMED-CT" : [ "163031004" ] }, "value" : { "scalar" : 80, "units" : "mmHg" }, "time" : 1287994563, "description" : "Diastolic" }, { "codes" : { "SNOMED-CT" : [ "105539002" ] }, "time" : 1269363119, "description" : "Tobacco Non-user" }, { "codes" : { "SNOMED-CT" : [ "225171007" ] }, "value" : { "scalar" : 22, "units" : null }, "time" : 1264479406, "description" : "BMI" } ], "procedures" : [ { "codes" : { "SNOMED-CT" : [ "12389009" ] }, "time" : 1239540900, "description" : "Breast cancer screening" } ], "medications" : [ { "codes" : { "RxNorm" : [ "857924" ] }, "time" : 1265256841, "description" : "Influenza Vaccine" }, { "codes" : { "RxNorm" : [ "854931" ] }, "time" : 1265256841, "description" : "Pneumonia Vaccine" } ] }')
Record.create(data)
Expand Down
10 changes: 10 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ def load_fixtures
`mongoimport -d #{Mongoid.master.name} -h #{Mongoid.master.connection.host_to_try[0]} --drop -c records test/fixtures/records.json`
end


end


def dump_database
Mongoid::Config.master.collections.each do |collection|
collection.drop unless collection.name.include?('system.')
end
end

dump_database

0 comments on commit bba8f19

Please sign in to comment.