<commit_before>require "spec_helper"

describe "/api/v1/farms" do
	let(:user) { create(:user) }
	let(:token) { user.authentication_token }

	before do
		user.add_role :user
		create(:farm, user: user, name: "Testfarm")
		create(:farm, name: "Access denied")
		@ability = Ability.new(user)
	end

	context "farms viewable by this logged-in user" do
		let(:url) { "/api/v1/farms" }
		it "json" do
			get "#{url}.json"

			farms_json = Farm.accessible_by(@ability).to_json

			assert last_response.ok?
			last_response.body.should eql(farms_json)
			last_response.status.should eql(200)

			farms = JSON.parse(last_response.body)

			farms.any? do |farm|
				farm["name"] == "Testfarm"
			end.should be_true

			farms.any? do |farm|
				farm["name"] == "Access denied"
			end.should be_true

		end
	end
end<commit_msg>Pass the authentication token with the GET request to sign in the user.<commit_after>require "spec_helper"

describe "/api/v1/farms" do
	let(:user) { create(:user) }
	let(:token) { user.authentication_token }

	before do
		user.add_role :user
		create(:farm, user: user, name: "Testfarm")
		create(:farm, name: "Access denied")
		@ability = Ability.new(user)
	end

	context "farms viewable by this logged-in user" do
		let(:url) { "/api/v1/farms" }
		it "json" do
			get "#{url}.json", auth_token: :token

			farms_json = Farm.accessible_by(@ability).to_json

			assert last_response.ok?
			last_response.body.should eql(farms_json)
			last_response.status.should eql(200)

			farms = JSON.parse(last_response.body)

			farms.any? do |farm|
				farm["name"] == "Testfarm"
			end.should be_true

			farms.any? do |farm|
				farm["name"] == "Access denied"
			end.should be_true

		end
	end
end
{'fraction_non_alphanumeric': 0.13716295427901523, 'fraction_numerical': 0.005861664712778429, 'mean_word_length': 3.8220338983050848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2979846', 'n_tokens_mistral': 723, 'n_tokens_neox': 632, 'n_words': 149}