Permalink
Browse files

Massive cleanup and bug fixing

  • Loading branch information...
lpic committed Apr 27, 2012
1 parent a4ecf08 commit 2227bfb9518f728e81f5ffcc03e455d4330dfe14
Showing with 283 additions and 1,566 deletions.
  1. +1 −3 .gitignore
  2. +17 −16 Gemfile
  3. +16 −14 Gemfile.lock
  4. BIN app/assets/images/rspec.jpg
  5. +5 −0 app/assets/stylesheets/application.css.scss
  6. +1 −0 app/controllers/application_controller.rb
  7. +12 −62 app/controllers/carts_controller.rb
  8. +22 −85 app/controllers/line_items_controller.rb
  9. +6 −51 app/controllers/orders_controller.rb
  10. +7 −58 app/controllers/payment_types_controller.rb
  11. +7 −58 app/controllers/products_controller.rb
  12. +1 −1 app/helpers/application_helper.rb
  13. +4 −5 app/models/ability.rb
  14. +1 −5 app/models/order.rb
  15. +1 −1 app/models/payment_type.rb
  16. +1 −1 app/models/product.rb
  17. +2 −2 app/models/user.rb
  18. +5 −5 app/views/carts/_form.html.erb
  19. +13 −5 app/views/layouts/application.html.erb
  20. +10 −13 app/views/line_items/_form.html.erb
  21. +1 −1 app/views/orders/_form.html.erb
  22. +1 −1 app/views/orders/index.html.erb
  23. +1 −1 app/views/orders/show.html.erb
  24. +8 −9 app/views/payment_types/_form.html.erb
  25. +2 −1 app/views/payment_types/show.html.erb
  26. +1 −1 app/views/products/who_bought.atom.builder
  27. +1 −1 app/views/products/who_bought.html.erb
  28. +0 −2 app/views/store/index.html.erb
  29. +0 −25 config/database.yml.sqlite
  30. +1 −5 db/migrate/20120322135425_add_cover_image_column.rb
  31. +0 −9 db/migrate/20120328141842_add_pay_type_id_for_order.rb
  32. +6 −0 db/migrate/20120328141842_add_payment_type_id_for_order.rb
  33. +1 −5 db/migrate/20120329134051_create_roles.rb
  34. +1 −1 db/migrate/{20120329134358_users_habtm_roles.rb → 20120329134358_create_roles_users.rb}
  35. +1 −1 db/migrate/20120330112217_remove_pay_type_from_orders.rb
  36. +7 −9 db/schema.rb
  37. +13 −8 db/seeds.rb
  38. 0 lib/tasks/{combine_items_migration.rb → combine_items_migration.rake}
  39. +9 −0 lib/tasks/test_seed.rake
  40. +0 −86 spec/controllers/carts_controller_spec.rb
  41. +0 −95 spec/controllers/line_items_controller_spec.rb
  42. +0 −189 spec/controllers/orders_controller_spec.rb
  43. +0 −164 spec/controllers/payment_types_controller_spec.rb
  44. +15 −87 spec/controllers/products_controller_spec.rb
  45. +7 −18 spec/controllers/store_controller_spec.rb
  46. +30 −29 spec/factories.rb
  47. +1 −3 spec/models/cart_spec.rb
  48. +0 −5 spec/models/payment_type_spec.rb
  49. +6 −5 spec/requests/orders_spec.rb
  50. +0 −11 spec/requests/payment_types_spec.rb
  51. +0 −35 spec/routing/payment_types_routing_spec.rb
  52. +22 −0 spec/spec_helper.rb
  53. +16 −0 spec/support/controller_macros.rb
  54. 0 test/fixtures/.gitkeep
  55. +0 −11 test/fixtures/carts.yml
  56. +0 −9 test/fixtures/line_items.yml
  57. +0 −23 test/fixtures/products.yml
  58. 0 test/functional/.gitkeep
  59. +0 −51 test/functional/carts_controller_test.rb
  60. +0 −50 test/functional/line_items_controller_test.rb
  61. +0 −66 test/functional/products_controller_test.rb
  62. +0 −14 test/functional/store_controller_test.rb
  63. 0 test/integration/.gitkeep
  64. +0 −12 test/performance/browsing_test.rb
  65. +0 −13 test/test_helper.rb
  66. 0 test/unit/.gitkeep
  67. +0 −28 test/unit/cart_test.rb
  68. +0 −4 test/unit/helpers/carts_helper_test.rb
  69. +0 −4 test/unit/helpers/line_items_helper_test.rb
  70. +0 −4 test/unit/helpers/products_helper_test.rb
  71. +0 −4 test/unit/helpers/store_helper_test.rb
  72. +0 −7 test/unit/line_item_test.rb
  73. +0 −74 test/unit/product_test.rb
View
@@ -14,7 +14,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
-/public/system/dragonfly/development/2012/*.meta
-
-Gemfile.lock
+/public/system/dragonfly/development/*/*/*/*.meta
View
33 Gemfile
@@ -5,34 +5,35 @@ gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'mysql2'
-gem 'execjs'
-gem 'therubyracer'
+gem 'mysql2', '0.3.11'
+gem 'execjs', '1.3.0'
+gem 'therubyracer', '0.9.10'
-gem 'factory_girl_rails', '1.0'
gem 'will_paginate', '~> 3.0'
+#gem 'web-app-theme', :git =>'git://github.com/pilu/web-app-theme.git'
-gem 'formtastic'
+gem 'formtastic', '1.2.4'
gem 'rack-cache', :require => 'rack/cache'
gem 'dragonfly', '~>0.9.11'
gem 'rmagick', :require => 'RMagick'
-gem 'devise'
-gem 'cancan'
+gem 'devise', '1.4.9'
+gem 'cancan', '1.6.7'
group :development do
- gem 'rspec-rails'
+ gem 'rspec-rails', '2.8.1'
gem 'annotate', '~> 2.4.1.beta'
- gem 'faker'
- #gem "validation_reflection", "~> 1.0.0"
+ gem 'faker', '1.0.1'
end
group :test do
- gem 'rspec'
- gem 'webrat'
- gem 'spork'
- gem 'autotest'
- gem 'autotest-standalone'
+ gem 'rspec', '2.8.0'
+ gem 'webrat', '0.7.3'
+ gem 'spork', '0.9.0'
+ gem 'autotest', '4.4.6'
+ gem 'autotest-standalone', '4.5.9'
+ gem 'factory_girl_rails', '1.0'
+ gem 'database_cleaner', '0.6.7'
end
# Gems used only for assets and not required
@@ -47,7 +48,7 @@ group :assets do
gem 'uglifier', '>= 1.0.3'
end
-gem 'jquery-rails'
+gem 'jquery-rails', '2.0.1'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
@@ -44,6 +44,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ database_cleaner (0.6.7)
devise (1.4.9)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
@@ -155,26 +156,27 @@ PLATFORMS
DEPENDENCIES
annotate (~> 2.4.1.beta)
- autotest
- autotest-standalone
- cancan
+ autotest (= 4.4.6)
+ autotest-standalone (= 4.5.9)
+ cancan (= 1.6.7)
coffee-rails (~> 3.2.1)
- devise
+ database_cleaner (= 0.6.7)
+ devise (= 1.4.9)
dragonfly (~> 0.9.11)
- execjs
+ execjs (= 1.3.0)
factory_girl_rails (= 1.0)
- faker
- formtastic
- jquery-rails
- mysql2
+ faker (= 1.0.1)
+ formtastic (= 1.2.4)
+ jquery-rails (= 2.0.1)
+ mysql2 (= 0.3.11)
rack-cache
rails (= 3.2.1)
rmagick
- rspec
- rspec-rails
+ rspec (= 2.8.0)
+ rspec-rails (= 2.8.1)
sass-rails (~> 3.2.3)
- spork
- therubyracer
+ spork (= 0.9.0)
+ therubyracer (= 0.9.10)
uglifier (>= 1.0.3)
- webrat
+ webrat (= 0.7.3)
will_paginate (~> 3.0)
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -42,6 +42,10 @@
padding: 1em;
background: white;
+ #logged {
+ color: #04f;
+ }
+
#flash_notice, #flash_alert, #flash_warning {
padding: 5px 8px;
margin: 10px 0;
@@ -142,3 +146,4 @@
}
}
}
+
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ respond_to :html
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
@@ -1,92 +1,42 @@
class CartsController < ApplicationController
load_and_authorize_resource
+ respond_to :js, :only => :destroy
- # GET /carts
- # GET /carts.json
- def index
- authorize! :read, @carts
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @carts }
- end
- end
-
- # GET /carts/1
- # GET /carts/1.json
def show
begin
+ @cart = current_cart
rescue ActiveRecord::RecordNotFound
logger.error "Attempt to access invalid cart #{params[:id]}"
redirect_to root_url, notice: 'Invalid cart'
else
if current_cart.line_items.empty?
- respond_to do |format|
- format.html { redirect_to root_url, notice: 'Your cart is currently empty' }
- format.json { render json: @cart }
- end
- else
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @cart }
+ respond_with @cart do |format|
+ format.html { redirect_to root_url, notice: 'Your cart is currently empty.' }
end
end
end
end
- # GET /carts/new
- # GET /carts/new.json
- def new
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @cart }
- end
- end
-
- # GET /carts/1/edit
- def edit
- end
-
- # POST /carts
- # POST /carts.json
def create
- respond_to do |format|
- if @cart.save
- format.html { redirect_to @cart, notice: 'Cart was successfully created.' }
- format.json { render json: @cart, status: :created, location: @cart }
- else
- format.html { render action: "new" }
- format.json { render json: @cart.errors, status: :unprocessable_entity }
- end
+ if @cart.save
+ flash[:notice] = "Cart was successfully created."
end
+ respond_with @cart
end
- # PUT /carts/1
- # PUT /carts/1.json
def update
- respond_to do |format|
- if @cart.update_attributes(params[:cart])
- format.html { redirect_to @cart, notice: 'Cart was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @cart.errors, status: :unprocessable_entity }
- end
+ @cart = current_cart
+ if @cart.update_attributes(params[:cart])
+ flash[:notice] = "Cart was successfully updated."
end
+ respond_with @cart
end
- # DELETE /carts/1
- # DELETE /carts/1.js
- # DELETE /carts/1.json
def destroy
@cart = current_cart
@cart.destroy
session[:cart_id] = nil
-
- respond_to do |format|
- format.html { redirect_to root_url }
- format.js { }
- format.json { head :ok }
- end
+ respond_with @cart, :location => root_url
end
end
@@ -1,116 +1,53 @@
class LineItemsController < ApplicationController
load_and_authorize_resource
+ respond_to :js, :only => [:create, :increment, :decrement]
- # GET /line_items
- # GET /line_items.json
- def index
- authorize! :read, @line_items
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @line_items }
- end
- end
-
- # GET /line_items/1
- # GET /line_items/1.json
- def show
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @line_item }
- end
- end
-
- # GET /line_items/new
- # GET /line_items/new.json
- def new
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @line_item }
- end
- end
-
- # GET /line_items/1/edit
- def edit
- end
-
- # POST /line_items
- # POST /line_items.js
- # POST /line_items.json
def create
+ session[:counter] = 0 unless session[:counter].nil?
+
@cart = current_cart
product = Product.find(params[:product])
@line_item = @cart.add_product(product)
- session[:counter] = 0 unless session[:counter].nil?
- respond_to do |format|
+ respond_with @line_item do |format|
if @line_item.save
- format.html { redirect_to store_url }
- format.js { @current_item = @line_item }
- format.json { render json: @line_item, status: :created, location: @line_item }
- else
- format.html { render action: "new" }
- format.json { render json: @line_item.errors, status: :unprocessable_entity }
+ format.html { redirect_to root_url }
+ format.js { @current_item = @line_item }
end
end
end
- # PUT /line_items/1
- # PUT /line_items/1.js
- # PUT /line_items/1.json
def increment
@cart = current_cart
@line_item = @cart.increment(params[:id])
- respond_to do |format|
- if @line_item.save
- format.html { redirect_to store_path, notice: 'Line item was successfully updated.' }
- format.js { @current_item = @line_item }
- format.json { head :ok }
- else
- format.html { render action: "edit" }
- format.json { render json: @line_item.errors, status: :unprocessable_entity }
- end
- end
+ respond_with @line_item do |format|
+ if @line_item.save
+ format.html { redirect_to root_path, notice: 'Line item was successfully updated.' }
+ format.js { @current_item = @line_item }
+ end
+ end
end
- # PUT /line_items/1
- # PUT /line_items/1.js
- # PUT /line_items/1.json
def decrement
@cart = current_cart
@line_item = @cart.decrement(params[:id])
- respond_to do |format|
- if @line_item.save
- format.html { redirect_to store_path, notice: 'Line item was successfully updated.' }
- format.js { @current_item = @line_item }
- format.json { head :ok }
- else
- format.html { render action: "edit" }
- format.json { render json: @line_item.errors, status: :unprocessable_entity }
- end
+ respond_with @line_item do |format|
+ if @line_item.save
+ format.html { redirect_to root_path, notice: 'Line item was successfully updated.' }
+ format.js { @current_item = @line_item }
+ end
end
end
- # PUT /line_items/1
- # PUT /line_items/1.json
def update
- respond_to do |format|
- if @line_item.update_attributes(params[:line_item])
- format.html { redirect_to @line_item, notice: 'Line item was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @line_item.errors, status: :unprocessable_entity }
- end
+ if @line_item.update_attributes(params[:line_item])
+ flash[:notice] = "Line item was successfully updated."
end
+ respond_with @line_item
end
- # DELETE /line_items/1
- # DELETE /line_items/1.json
def destroy
- respond_to do |format|
- format.html { redirect_to current_cart, notice: 'Item deleted' }
- format.json { head :no_content }
- end
+ flash[:notice] = "Item deleted."
+ respond_with @line_item
end
-
end
Oops, something went wrong.

0 comments on commit 2227bfb

Please sign in to comment.