-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add context to Page #2457
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
base: main
Are you sure you want to change the base?
Add context to Page #2457
Changes from all commits
2826f1e
cdd4388
b68bc74
178a9b7
44f6e0f
a65b941
4680463
486ca49
2856182
21e5d17
01fd712
432eb0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
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. Why the changes to this file? They seem unrelated. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ | |
| describe Admin::CustomersController, type: :controller do | ||
| describe "GET index" do | ||
| it "passes all customers to the view" do | ||
| customer = create(:customer) | ||
| customers = create_list(:customer, 5) | ||
|
|
||
| locals = capture_view_locals { get :index } | ||
| expect(locals[:resources]).to eq([customer]) | ||
| expect(locals[:resources]).to eq(customers) | ||
| end | ||
|
|
||
| it "applies any scope overrides" do | ||
|
|
@@ -47,6 +47,22 @@ | |
| expect(locals[:resources].map(&:id)).to eq customers.map(&:id).sort | ||
| end | ||
|
|
||
| context "when the user is an admin" do | ||
| controller(Admin::CustomersController) do | ||
| def authenticate_admin | ||
| @current_user = Customer.last | ||
|
Collaborator
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. This is unreliable to get the "last" customer, which you expect to be the |
||
| end | ||
| end | ||
|
|
||
| it "passes one customers to the view" do | ||
| _other_customers = create_list(:customer, 5) | ||
| customer = create(:customer) | ||
|
|
||
| locals = capture_view_locals { get :index } | ||
| expect(locals[:resources]).to eq([customer]) | ||
| end | ||
| end | ||
|
|
||
| context "with alternate sorting attributes" do | ||
| controller(Admin::CustomersController) do | ||
| def default_sorting_attribute | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,8 @@ def pundit_user | |
| end | ||
|
|
||
| describe "GET new" do | ||
| it "raises a Pundit error" do | ||
| expect { get :new }.to raise_error(Pundit::NotAuthorizedError) | ||
| it "allows access to /new" do | ||
| expect { get :new }.not_to raise_error | ||
|
Collaborator
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. Something that I'm not sure about with this is that it removes a place where this type of authorization error is tested. Although the specs are a mess anyway already so things like this are difficult to avoid. Perhaps a case for Also, the context setup at the top ( |
||
| end | ||
| end | ||
|
|
||
|
|
@@ -106,5 +106,34 @@ def send_request(order:) | |
| end | ||
| end | ||
| end | ||
|
|
||
| context "when the user is not an admin" do | ||
| controller(Admin::OrdersController) do | ||
| def pundit_user | ||
| Customer.find_by(name: "Current User") | ||
| end | ||
| end | ||
|
|
||
| let!(:user) { create(:customer, name: "Current User") } | ||
|
|
||
| describe "GET new" do | ||
| it "allows access to /new" do | ||
| expect { get :new }.not_to raise_error | ||
| end | ||
| end | ||
|
|
||
| describe "POST create" do | ||
| it "allows creating records with the current customer" do | ||
| post( | ||
| :create, | ||
| params: { | ||
| order: attributes_for(:order) | ||
| } | ||
| ) | ||
| expect(response).to redirect_to([:admin, (order = Order.last)]) | ||
| expect(order.customer).to eq(user) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| # standard:enable Lint/ConstantDefinitionInBlock | ||
Uh oh!
There was an error while loading. Please reload this page.