Sha256: bf552428d217d47dc71dbf903d128410e9bf1f2c62d99036d99528cbad93adfd

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

require "rails_helper"

RSpec.describe "client request spec", :client => true, :type => :request do 

	before(:all) do 
		## create a confirmed user
		@u = User.new(attributes_for(:user_confirmed))
        @u.save
		## create another confirmed user
		@u2 = User.new(attributes_for(:user_confirmed))
		@u2.save
		## create a confirmed admin user
		@admin = User.new(attributes_for(:admin_confirmed))
		@admin.save
	end

	context " -- json requests -- " do 
		it " -- does not respond to json request -- " do 
			get auth_client_path(:id => @u.id.to_s),nil,{ "CONTENT_TYPE" => "application/json" , "ACCEPT" => "application/json"}
			expect(response.code).to eq("401")
		end
	end

	context " -- web app requests -- " do 
		it " -- returns not authenticated if no one is signed in -- " do 

			get auth_client_path(:id => @u.id.to_s)
			expect(response).to redirect_to(new_user_session_path)
		end

		it " -- returns not allowed if client belongs to another user -- " do 

			sign_in(@u2)
			get auth_client_path(:id => @u.id.to_s)
			expect(response.body).to eq("client does not belong to user")

		end

		it " -- goes through if admin is looking at a users client -- " do 
			sign_in(@admin)
			get auth_client_path(:id => @u.id.to_s)
			expect(response.code).to eq("200")
		end

		it " -- shows the client -- " do 
			sign_in(@u)
			get auth_client_path(:id => @u.id.to_s)
			expect(response.code).to eq("200")
			client = assigns(:client)
			expect(client.resource_id.to_s).to eq(@u.id.to_s)
		end

		it " -- updates the client with an app id if add_app_id is passed into the update request.", :client_update => true do 
			sign_in(@u)
			client = Auth::Client.find(@u.id.to_s)
			
			put auth_client_path(:id => @u.id.to_s), :client => {:add_app_id => "anything"}
			
			expect(response.code).to eq("200")
			client = assigns(:client)
			expect(client.app_ids).not_to be_empty
		end
	end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wordjelly-auth-1.4.0 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.9 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.8 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.7 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.6 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.5 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.3 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.2 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.1 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.3.0 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.2.9 spec/requests/user/client_request_spec.rb