Browse Source

Iteration F3.

master
Nils Dittberner 9 years ago
parent
commit
671688db49
7 changed files with 25 additions and 2 deletions
  1. +1
    -0
      Gemfile
  2. +3
    -0
      Gemfile.lock
  3. +1
    -0
      app/assets/javascripts/application.js
  4. +1
    -1
      app/controllers/line_items_controller.rb
  5. +5
    -1
      app/views/line_items/_line_item.html.erb
  6. +3
    -0
      app/views/line_items/create.js.erb
  7. +11
    -0
      test/controllers/line_items_controller_test.rb

+ 1
- 0
Gemfile View File

@@ -18,6 +18,7 @@ gem 'coffee-rails', '~> 4.2'

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder


+ 3
- 0
Gemfile.lock View File

@@ -63,6 +63,8 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -158,6 +160,7 @@ DEPENDENCIES
coffee-rails (~> 4.2)
jbuilder (~> 2.5)
jquery-rails
jquery-ui-rails
listen (~> 3.0.5)
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)


+ 1
- 0
app/assets/javascripts/application.js View File

@@ -11,6 +11,7 @@
// about supported directives.
//
//= require jquery
//= require jquery-ui/effect-blind
//= require jquery_ujs
//= require turbolinks
//= require_tree .

+ 1
- 1
app/controllers/line_items_controller.rb View File

@@ -34,7 +34,7 @@ class LineItemsController < ApplicationController
respond_to do |format|
if @line_item.save
format.html { redirect_to @line_item.cart }
format.js
format.js { @current_item = @line_item }
format.json { render :show, status: :created, location: @line_item }
else
format.html { render :new }


+ 5
- 1
app/views/line_items/_line_item.html.erb View File

@@ -1,4 +1,8 @@
<tr>
<% if line_item == @current_item %>
<tr id="current_item">
<% else %>
<tr>
<% end %>
<td><%= line_item.quantity %> &times;</td>
<td><%= line_item.product.title %></td>
<td class="item_price"><%= number_to_currency(line_item.total_price) %></td>


+ 3
- 0
app/views/line_items/create.js.erb View File

@@ -1 +1,4 @@
$('#cart').html("<%=j render(@cart) %>")

$('#current_item').css({'background-color':'#88ff88'})
.animate({'background-color':'#114411'}, 1000)

+ 11
- 0
test/controllers/line_items_controller_test.rb View File

@@ -26,6 +26,17 @@ class LineItemsControllerTest < ActionDispatch::IntegrationTest
assert_select 'td', 'Programming Ruby 1.9'
end

test "should create line_item via ajax" do
assert_difference('LineItem.count') do
post line_items_url, params: { product_id: products(:ruby).id }, xhr: true
end

assert_response :success
assert_select_jquery :html, '#cart' do
assert_select 'tr#current_item td', /Programming Ruby 1.9/
end
end

test "should show line_item" do
get line_item_url(@line_item)
assert_response :success


Loading…
Cancel
Save