-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rspec for product controller, update account controller
- Loading branch information
1 parent
f1da899
commit beeb1bc
Showing
11 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,7 @@ DEPENDENCIES | |
byebug | ||
capybara | ||
config | ||
connection_pool | ||
cssbundling-rails (~> 1.4) | ||
debug | ||
dotenv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,29 @@ | |
|
||
describe "POST #create" do | ||
context "with valid attributes" do | ||
before { post :create, params: { account: attributes_for(:account) } } | ||
let(:valid_params) do | ||
{ | ||
account: { | ||
name: "Test User", | ||
email: "[email protected]", | ||
address: "123 Test Street", | ||
phone_number: "1234567890", | ||
password: "password", | ||
password_confirmation: "password" | ||
} | ||
} | ||
end | ||
|
||
before { post :create, params: valid_params } | ||
|
||
it "creates a new account" do | ||
expect(assigns(:account).id).to(be_present) | ||
expect(Account.last).to(have_attributes( | ||
name: "Test User", | ||
email: "[email protected]", | ||
address: "123 Test Street", | ||
phone_number: "1234567890" | ||
) | ||
) | ||
end | ||
|
||
it "redirects to root path" do | ||
|
@@ -33,11 +52,21 @@ | |
end | ||
|
||
context "with invalid attributes" do | ||
before do | ||
invalid_attributes = attributes_for(:account).merge(name: nil, email: "invalid_email", password: "123", password_confirmation: "123456") | ||
post :create, params: { account: invalid_attributes } | ||
let(:invalid_attributes) do | ||
{ | ||
account: { | ||
name: "", | ||
email: "", | ||
address: "", | ||
phone_number: "", | ||
password: "", | ||
password_confirmation: "" | ||
} | ||
} | ||
end | ||
|
||
before { post :create, params: invalid_attributes } | ||
|
||
it "does not save the new account" do | ||
expect(assigns(:account).id).not_to(be_present) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe(ProductsController, type: :controller) do | ||
describe "GET #index" do | ||
let!(:products) do | ||
FactoryBot.create_list(:product, Settings.DIGIT_10) | ||
end | ||
|
||
before { get :index } | ||
|
||
it "assigns @pagy and @products" do | ||
expect(assigns(:pagy).count).to(eq(Settings.DIGIT_10)) | ||
products_per_page = Settings.PAGE_9 | ||
expect(assigns(:products).count).to(eq(products_per_page)) | ||
end | ||
|
||
it "renders the index template" do | ||
expect(response).to(render_template(:index)) | ||
end | ||
end | ||
|
||
describe "GET #show" do | ||
context "when product exists" do | ||
let!(:product) { FactoryBot.create(:product) } | ||
|
||
before do | ||
get :show, params: { id: product.id } | ||
end | ||
|
||
it "assigns the requested product to @product" do | ||
expect(assigns(:product)).to(eq(product)) | ||
end | ||
|
||
it "renders the show template" do | ||
expect(response).to(render_template("show")) | ||
end | ||
end | ||
|
||
context "when product does not exist" do | ||
before { get :show, params: { id: 0 } } | ||
|
||
it "flash error if product doesn't exist" do | ||
expect(flash[:error]).to(eq(I18n.t("products.load.error"))) | ||
end | ||
|
||
it "redirects to products_path if product is not found" do | ||
expect(response).to(redirect_to(products_path)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.