Skip to content

Commit

Permalink
Merge pull request #168 from jalena-penaligon/25-users-must-login-to-…
Browse files Browse the repository at this point in the history
…checkout

User Story 25: Users Must Login or Register to Checkout
  • Loading branch information
hsmitha26 authored Apr 8, 2019
2 parents 5425ba8 + 3a78ad5 commit 0c32005
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/views/carts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<% if session[:cart] != nil && current_user == nil %>
<section id="login-message">
You must <%= link_to 'login', login_path %> or
<%= link_to 'register', register_path %> to checkout.
</section>
<% end %>
<% if session[:cart] != nil %>
<% @cart.contents.each do |id| %>
<section id="item-<%= id[0].to_i %>">
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</nav>

<% flash.each do |type, message| %>
<p><%= message %></p>
<p class="flash"><%= message %></p>
<% end %>
<%= yield %>
Expand Down
27 changes: 26 additions & 1 deletion spec/features/cart/cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
visit cart_path

click_link "Add One"

expect(page).to have_content("Quantity: 2")
end
end
Expand All @@ -163,5 +163,30 @@
end
end
end

describe 'as a visitor' do
describe 'if I have items in my cart' do
it 'displays a message, with links, that you need to login or register' do
item_1 = create(:item, id: 1, current_price: 3.0)

visit item_path(item_1)
click_link "Add to Cart"

visit cart_path

within "#login-message" do
expect(page).to have_content("You must login or register to checkout.")

click_link "login"
expect(current_path).to eq(login_path)

visit cart_path

click_link "register"
expect(current_path).to eq(register_path)
end
end
end
end
end
end

0 comments on commit 0c32005

Please sign in to comment.