Sha256: 2b553318ddbf26e134b6f2103f34a8cf5dd5e93d3f453170f0688213a342a7e6

Contents?: true

Size: 1.88 KB

Versions: 19

Compression:

Stored size: 1.88 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),params: nil,headers: { "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), params: {: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

19 entries across 19 versions & 1 rubygems

Version Path
wordjelly-auth-1.6.0 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.9 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.8 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.7 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.6 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.5 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.4 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.3 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.2 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.1 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.5.0 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.9 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.8 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.7 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.6 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.5 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.4 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.3 spec/requests/user/client_request_spec.rb
wordjelly-auth-1.4.2 spec/requests/user/client_request_spec.rb