only let them order one thing (for now)

This commit is contained in:
Skud committed 2013-05-16 20:58:43 +10:00
1 parent a5e022790d
commit 4dca148cbf
5 files changed
+82 -25

No files matched your search

+16
View File
@@ -2,6 +2,22 @@ class ShopController < ApplicationController
def index
@products = Product.all
@order_item = OrderItem.new
# this is (hopefully) part of a short-term hack to prevent people from
# ordering multiple subscriptions, which would be very confusing to deal
# with. We check whether they have an order already in progress, and if
# so, point that out to them and encourage them to checkout, rather than
# letting them add more stuff to their order.
@order = nil
@most_recent_item = nil
if current_member
@order = current_member.current_order
if @order
@most_recent_item = @order.order_items.first
end
end
respond_to do |format|
format.html # index.html.haml
end
+3
View File
@@ -2,4 +2,7 @@ class Product < ActiveRecord::Base
attr_accessible :description, :min_price, :name
has_and_belongs_to_many :orders
def to_s
name
end
end
+39 -25
View File
@@ -13,36 +13,50 @@
you want to pay. Remember, your subscription supports an open source
platform promoting sustainable lifestyles!
- @products.each do |p|
%h2= p.name
- if @order and @order.order_items.count > 0
%h2 Your current order
%div
:markdown
#{ strip_tags p.description }
%p
You currently have the following item in your cart:
%strong
= @most_recent_item.product
@
= price_with_currency(@most_recent_item.price)
%p
Pay what you want, starting at
=succeed "." do
=price_with_currency(p.min_price)
= link_to "View order and checkout", order_path(@order)
%div
- if can? :create, Order
- else
- @products.each do |p|
%h2= p.name
= form_for @order_item do |f|
.field
= f.text_field :price, :value => price_in_dollars(p.min_price)
.field
= f.hidden_field :product_id, :value => p.id
.field
= f.hidden_field :quantity, :value => 1
.actions
= f.submit 'Buy', :class => 'btn btn-primary'
%div
:markdown
#{ strip_tags p.description }
- else
Please
=link_to "sign in", new_member_session_path
or
=link_to "sign up", new_member_registration_path
to purchase.
%p
Pay what you want, starting at
=succeed "." do
=price_with_currency(p.min_price)
%div
- if can? :create, Order
= form_for @order_item do |f|
.field
= f.text_field :price, :value => price_in_dollars(p.min_price)
.field
= f.hidden_field :product_id, :value => p.id
.field
= f.hidden_field :quantity, :value => 1
.actions
= f.submit 'Buy', :class => 'btn btn-primary'
- else
Please
=link_to "sign in", new_member_session_path
or
=link_to "sign up", new_member_registration_path
to purchase.
+19
View File
@@ -12,6 +12,25 @@ describe ShopController do
get :index, {}
assigns(:products).should eq([@product1, @product2])
end
it "assigns a new @order_item to build forms" do
get :index, {}
assigns(:order_item).should be_an_instance_of OrderItem
end
it "assigns @order as nil if the user doesn't have one" do
get :index, {}
assigns(:order).should be_nil
end
it "assigns @order as current_order if there is one" do
@member = FactoryGirl.create(:member)
sign_in @member
@order = FactoryGirl.create(:order, :member => @member)
get :index, {}
assigns(:order).should eq @order
end
end
end
+5
View File
@@ -1,4 +1,9 @@
require 'spec_helper'
describe Product do
it "stringifies using the name" do
@product = FactoryGirl.create(:product)
@product.to_s.should eq @product.name
end
end