-
-
Notifications
You must be signed in to change notification settings - Fork 724
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
[BUU] Fix non-admin saving #12412
[BUU] Fix non-admin saving #12412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import "@hotwired/turbo"; | ||
|
||
document.addEventListener("turbo:frame-missing", (event) => { | ||
// don't replace frame contents | ||
event.preventDefault(); | ||
|
||
// show error message instead | ||
status = event.detail.response.status; | ||
if(status == 401) { | ||
alert(I18n.t("errors.unauthorized.message")); | ||
} else { | ||
alert(I18n.t("errors.general_error.message")); | ||
} | ||
}); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ | |
|
||
require "system_helper" | ||
|
||
describe 'As an admin, I can manage products', feature: :admin_style_v3 do | ||
describe 'As an enterprise user, I can manage my products', feature: :admin_style_v3 do | ||
include WebHelper | ||
include AuthenticationHelper | ||
include FileHelper | ||
|
||
let(:producer) { create(:supplier_enterprise) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In many places the codebase says "supplier". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I didn't actually know this. "Supplier" is a bit more general. The enterprise may not be producing the product. 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall having a conversation in Slack I think, and that "producer" was the winner. I can't find that conversation though, so now I'm not sure! I will seek clarification in #product-circle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the conversation https://openfoodnetwork.slack.com/archives/C01T75H6G0Z/p1679368367236359 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Sigmund, I forgot my own comments! 😅 I'm going to write it on a post-it note on my computer screen.. |
||
let(:user) { create(:user, enterprises: [producer]) } | ||
|
||
before do | ||
login_as_admin | ||
login_as user | ||
end | ||
|
||
it "can see the new product page" do | ||
|
@@ -129,8 +132,10 @@ | |
before { create_products 1 } | ||
|
||
# create a product with a different supplier | ||
let!(:producer) { create(:supplier_enterprise, name: "Producer 1") } | ||
let!(:product_by_supplier) { create(:simple_product, name: "Apples", supplier: producer) } | ||
let!(:producer1) { create(:supplier_enterprise, name: "Producer 1") } | ||
let!(:product_by_supplier) { create(:simple_product, name: "Apples", supplier: producer1) } | ||
|
||
before { user.enterprise_roles.create(enterprise: producer1) } | ||
|
||
it "can search for and update a product" do | ||
visit admin_products_url | ||
|
@@ -173,7 +178,7 @@ | |
search_by_category "Category 1" | ||
|
||
# expect(page).to have_content "1 product found for your search criteria." | ||
expect(page).to have_select "category_id", selected: "Category 1" | ||
expect(page).to have_select "category_id", selected: "Category 1" # fails in dev but not CI | ||
expect_products_count_to_be 1 | ||
expect(page).to have_field "Name", with: product_by_category.name | ||
end | ||
|
@@ -974,7 +979,7 @@ | |
|
||
def create_products(amount) | ||
amount.times do |i| | ||
create(:simple_product, name: "product #{i}") | ||
create(:simple_product, name: "product #{i}", supplier: producer) | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in Rails we arrange code like this in a folder called
initializers
. Maybe we could do the same with JS next time.