Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: missing barcode spec #4352

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions spec/requests/barcode_items_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
RSpec.describe "BarcodeItems", type: :request do
let(:default_params) do
{ organization_name: @organization.to_param }
end
RSpec.describe "BarcodeItems", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }
let(:organization_admin) { create(:organization_admin, organization: organization) }

let(:default_params) { { organization_name: organization.to_param } }

context "While signed in" do
before do
sign_in(@user)
sign_in(user)
end

describe "GET #index" do
Expand All @@ -14,7 +16,7 @@
response
end

before { create(:barcode_item) }
before { create(:barcode_item, organization: organization) }

context "html" do
let(:response_format) { 'html' }
Expand Down Expand Up @@ -70,8 +72,9 @@

describe "GET #find" do
let!(:global_barcode) { create(:global_barcode_item) }
let!(:organization_barcode) { create(:barcode_item, organization: @organization) }
let!(:other_barcode) { create(:barcode_item, organization: create(:organization)) }
let!(:organization_barcode) { create(:barcode_item, organization: organization) }
let(:other_organization) { create(:organization, skip_items: true) }
let!(:other_barcode) { create(:barcode_item, organization: other_organization) }

context "via ajax" do
it "can find a barcode that is scoped to just this organization" do
Expand Down Expand Up @@ -101,8 +104,8 @@

describe "DELETE #destroy" do
it "disallows a user to delete someone else's barcode" do
other_org = create(:organization)
other_barcode = create(:barcode_item, organization_id: other_org.id)
other_org = create(:organization, skip_items: true)
other_barcode = create(:barcode_item, organization: other_org)
delete barcode_item_path(default_params.merge(id: other_barcode.to_param))
expect(response).not_to be_successful
expect(response).to have_error(/permission/)
Expand All @@ -118,13 +121,13 @@
end

it "redirects to the index" do
delete barcode_item_path(default_params.merge(id: create(:barcode_item, organization_id: @organization.id)))
delete barcode_item_path(default_params.merge(id: create(:barcode_item, organization_id: organization.id)))
expect(subject).to redirect_to(barcode_items_path)
end
end

context "Looking at a different organization" do
let(:object) { create(:barcode_item, organization: create(:organization)) }
let(:object) { create(:barcode_item, organization: create(:organization, skip_items: true)) }
include_examples "requiring authorization"
end
end
Expand Down