Skip to content

Commit

Permalink
Complete user story (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
chsweet committed Jul 28, 2021
1 parent 99c261e commit 3620a1b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
12 changes: 9 additions & 3 deletions app/controllers/admin/merchants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ def edit

def update
merchant = Merchant.find(params[:id])
merchant.update(name: params[:name])
flash[:notice] = "Merchant Sucessfully Updated"
redirect_to admin_merchant_path(merchant)

if params[:status]
merchant.update(status: params[:status])
redirect_to admin_merchants_path
elsif params[:new_name]
merchant.update(name: params[:new_name])
flash[:notice] = "Merchant Sucessfully Updated"
redirect_to admin_merchant_path(merchant)
end
end
end
8 changes: 8 additions & 0 deletions app/views/admin/merchants/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<% @merchants.each do |merchant| %>
<section id="merchant-<%= merchant.id %>">
<%= link_to "#{merchant.name}", admin_merchant_path(merchant) %>
<br>
<% if merchant.status == "disabled" %>
<%= button_to 'Enable', admin_merchant_path(merchant), params: {status: 'enabled'}, method: :patch%>
<% else merchant.status == "enabled"%>
<%= button_to 'Disable', admin_merchant_path(merchant), params: {status: 'disabled'}, method: :patch%>
<% end %>
</section>
<% end %>
46 changes: 38 additions & 8 deletions spec/features/admin/merchants/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,48 @@

RSpec.describe 'admin merchants index page' do
before :each do
@merchants_1 = create(:merchant)
@merchants_2 = create(:merchant)
@merchants_3 = create(:merchant)
@merchants_4 = create(:merchant)
@merchant_1 = create(:merchant, status: 'enabled')
@merchant_2 = create(:merchant)
@merchant_3 = create(:merchant, status: 'enabled')
@merchant_4 = create(:merchant)
end

it 'displays all of the merchants' do
visit admin_merchants_path

expect(page).to have_content(@merchants_1.name)
expect(page).to have_content(@merchants_2.name)
expect(page).to have_content(@merchants_3.name)
expect(page).to have_content(@merchants_4.name)
expect(page).to have_content(@merchant_1.name)
expect(page).to have_content(@merchant_2.name)
expect(page).to have_content(@merchant_3.name)
expect(page).to have_content(@merchant_4.name)
end

it 'displays a button to endable merchant with disabled status and update status' do
visit admin_merchants_path

within ("#merchant-#{@merchant_2.id}") do
click_button('Enable')
end

expect(current_path).to eq(admin_merchants_path)

within ("#merchant-#{@merchant_2.id}") do
expect(page).to_not have_button('Enable')
expect(page).to have_button('Disable')
end
end

it 'displays a button to disable merchant with enabled status and update status' do
visit admin_merchants_path

within ("#merchant-#{@merchant_1.id}") do
click_button('Disable')
end

expect(current_path).to eq(admin_merchants_path)

within ("#merchant-#{@merchant_1.id}") do
expect(page).to_not have_button('Disable')
expect(page).to have_button('Enable')
end
end
end

0 comments on commit 3620a1b

Please sign in to comment.