Skip to content

Commit

Permalink
Feat: user story #15 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
lisataylor5472 committed Feb 20, 2022
1 parent 6125aa5 commit a140649
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
17 changes: 17 additions & 0 deletions app/controllers/admin/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
class Admin::MerchantsController < ApplicationController
#reason to have 2 merchant controllers -- encapsulates methods within the Admin realm in a separate controller
def index
@merchants = Merchant.all
end

def show
@merchant = Merchant.find(params[:id])
end

def edit
@merchant = Merchant.find(params[:id])
end

def update
merchant = Merchant.find(params[:id])
merchant.update(merchant_params)
redirect_to "/admin/merchants/#{merchant.id}"
flash[:notice] = "Successfully Updated Merchant Information"
end

private
def merchant_params
params.require(:merchant).permit(:name, :status)
end
end
5 changes: 5 additions & 0 deletions app/views/admin/merchants/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= form_with model: [:admin, @merchant], local: true do |form| %>
<%= form.label :name %>
<%= form.text_field :name, required: :true %>
<%= form.submit "Update Merchant" %>
<% end %>
11 changes: 8 additions & 3 deletions app/views/admin/merchants/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<div id="merchant_show-<%=@merchant.id%>">
<p><%= @merchant.name %>
</div>
<div id="merchant_show-<%=@merchant.id%>">
<h1><%= @merchant.name %></h1>
<p><%= link_to "Update Merchant", "/admin/merchants/#{@merchant.id}/edit" %></p>
</div>

<% if flash.any? %>
<%= flash[:notice] %>
<% end %>
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
get '/merchants/:id/dashboard', to: 'merchants#dashboard'
get '/merchants/:id/invoices', to: 'merchant_invoices#index'

get 'admin/merchants', to: 'admin/merchants#index'
get 'admin/merchants/:id', to: 'admin/merchants#show'
namespace :admin do
resources :merchants
end
end
5 changes: 3 additions & 2 deletions spec/features/admin/merchants/show_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe 'Admin Merchants Show' do
RSpec.describe 'Admin Merchants Show Page' do
describe 'user story #16' do
it "when clicking merchant name I am directed to that merchants show page" do
merchant_1 = Merchant.create!(name: "LT's Tee Shirts LLC")
Expand Down Expand Up @@ -40,7 +40,8 @@
it "updates are submitted - redirected back to admin/merchant show page w/ updated info and flash message" do
merchant_1 = Merchant.create!(name: "LT's Tee Shirts LLC")
visit "/admin/merchants/#{merchant_1.id}/edit"
fill_in 'Name', with: "LT's T-shirts and Hoodies LLC"

fill_in "Name", with: "LT's T-shirts and Hoodies LLC"
click_button("Update Merchant")

expect(current_path).to eq("/admin/merchants/#{merchant_1.id}")
Expand Down
17 changes: 7 additions & 10 deletions spec/features/admin/merchants/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

RSpec.describe 'Admin Merchants Edit' do
describe 'user story #15 - continued' do
before :each do
@merchant_1 = Merchant.create!(name: "LT's Tee Shirts LLC")
visit "/admin/merchants/#{@merchant_1.id}/edit"
end
it "submits the edit form and udpates merchant" do
merchant_1 = Merchant.create!(name: "LT's Tee Shirts LLC")

visit "/admin/merchants/#{merchant_1.id}"

fill_in 'Name', with: "LT's T-shirts and Hoodies LLC"
click_button 'Update Merchant'

expect(current_path).to eq("/admin/merchants/#{merchant_1.id}")
expect(current_path).to eq("/admin/merchants/#{@merchant_1.id}")
expect(page).to have_content("LT's T-shirts and Hoodies LLC")
expect(page).to have_content("Successfully Updated Merchant Information")
end

it 'all info not updated - yeilds an error' do
merchant_1 = Merchant.create!(name: "LT's Tee Shirts LLC")
visit edit_admin_merchant_path(merchant_1.id)
click_button 'Update Merchant'

expect(current_path).to eq("/admin/merchants/#{merchant_1.id}")
expect(page).to have_content("Error:")
expect(page).to have_content("LT's T-shirts and Hoodies LLC")
expect(current_path).to eq("/admin/merchants/#{@merchant_1.id}")
expect(page).to have_content("LT's Tee Shirts LLC")
end
end
end

0 comments on commit a140649

Please sign in to comment.