diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb
index 85e2e465b..50c5c67a0 100644
--- a/app/controllers/shop_controller.rb
+++ b/app/controllers/shop_controller.rb
@@ -1,2 +1,8 @@
class ShopController < ApplicationController
+ def index
+ @products = Product.all
+ respond_to do |format|
+ format.html # index.html.haml
+ end
+ end
end
diff --git a/app/views/shop/index.html.haml b/app/views/shop/index.html.haml
index da1f41c0a..409373444 100644
--- a/app/views/shop/index.html.haml
+++ b/app/views/shop/index.html.haml
@@ -1,2 +1,27 @@
-content_for :title, 'Shop'
+%p
+ Growstuff relies on your support to build and run this open source
+ platform for food growers.
+
+%p
+ We offer paid accounts which have access to exclusive features. You can
+ buy a monthly, yearly, or permanent ("seed") account.
+
+%p
+ All our accounts are priced on a sliding scale. You can choose how much
+ you want to pay. Remember, your subscription supports an open source
+ platform promoting sustainable lifestyles!
+
+- @products.each do |p|
+ %h2= p.name
+
+ %div
+ :markdown
+ #{ strip_tags p.description }
+
+ %div
+ Base price:
+ #{ number_with_precision(p.min_price, :precision => 2) }
+ #{ Growstuff::Application.config.currency }
+
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 1ee8742f6..76d4a5ded 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -51,5 +51,6 @@ Growstuff::Application.configure do
Growstuff::Application.configure do
config.site_name = "Growstuff (dev)"
config.analytics_code = ''
+ config.currency = 'AUD'
end
end
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 03d206851..a97654cc6 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -85,6 +85,7 @@ Growstuff::Application.configure do
eos
+ config.currency = 'AUD'
end
end
diff --git a/config/environments/staging.rb b/config/environments/staging.rb
index 1ad079660..1085a2ef0 100644
--- a/config/environments/staging.rb
+++ b/config/environments/staging.rb
@@ -81,6 +81,7 @@ Growstuff::Application.configure do
Growstuff::Application.configure do
config.site_name = "Growstuff (staging)"
config.analytics_code = ''
+ config.currency = 'AUD'
end
end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index 5f48eccfa..57e8c5d1a 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -43,6 +43,7 @@ Growstuff::Application.configure do
Growstuff::Application.configure do
config.site_name = "Growstuff (test)"
config.analytics_code = ''
+ config.currency = 'AUD'
end
end
diff --git a/config/routes.rb b/config/routes.rb
index 42a68df17..0ed446792 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,9 +1,5 @@
Growstuff::Application.routes.draw do
- resources :orders
-
- resources :products
-
devise_for :members, :controllers => { :registrations => "registrations" }
resources :authentications
@@ -17,6 +13,8 @@ Growstuff::Application.routes.draw do
resources :roles
resources :forums
resources :notifications
+ resources :orders
+ resources :products
get "home/index"
diff --git a/spec/controllers/orders_controller_spec.rb b/spec/controllers/orders_controller_spec.rb
index d9d5e8406..40da86b21 100644
--- a/spec/controllers/orders_controller_spec.rb
+++ b/spec/controllers/orders_controller_spec.rb
@@ -1,8 +1,9 @@
require 'spec_helper'
-
describe OrdersController do
+ login_member(:admin_member)
+
def valid_attributes
{ "member_id" => "MyString" }
end
@@ -14,7 +15,7 @@ describe OrdersController do
describe "GET index" do
it "assigns all orders as @orders" do
order = Order.create! valid_attributes
- get :index, {}, valid_session
+ get :index, {}
assigns(:orders).should eq([order])
end
end
@@ -22,14 +23,14 @@ describe OrdersController do
describe "GET show" do
it "assigns the requested order as @order" do
order = Order.create! valid_attributes
- get :show, {:id => order.to_param}, valid_session
+ get :show, {:id => order.to_param}
assigns(:order).should eq(order)
end
end
describe "GET new" do
it "assigns a new order as @order" do
- get :new, {}, valid_session
+ get :new, {}
assigns(:order).should be_a_new(Order)
end
end
@@ -37,7 +38,7 @@ describe OrdersController do
describe "GET edit" do
it "assigns the requested order as @order" do
order = Order.create! valid_attributes
- get :edit, {:id => order.to_param}, valid_session
+ get :edit, {:id => order.to_param}
assigns(:order).should eq(order)
end
end
@@ -46,18 +47,18 @@ describe OrdersController do
describe "with valid params" do
it "creates a new Order" do
expect {
- post :create, {:order => valid_attributes}, valid_session
+ post :create, {:order => valid_attributes}
}.to change(Order, :count).by(1)
end
it "assigns a newly created order as @order" do
- post :create, {:order => valid_attributes}, valid_session
+ post :create, {:order => valid_attributes}
assigns(:order).should be_a(Order)
assigns(:order).should be_persisted
end
it "redirects to the created order" do
- post :create, {:order => valid_attributes}, valid_session
+ post :create, {:order => valid_attributes}
response.should redirect_to(Order.last)
end
end
@@ -66,14 +67,14 @@ describe OrdersController do
it "assigns a newly created but unsaved order as @order" do
# Trigger the behavior that occurs when invalid params are submitted
Order.any_instance.stub(:save).and_return(false)
- post :create, {:order => { "member_id" => "invalid value" }}, valid_session
+ post :create, {:order => { "member_id" => "invalid value" }}
assigns(:order).should be_a_new(Order)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Order.any_instance.stub(:save).and_return(false)
- post :create, {:order => { "member_id" => "invalid value" }}, valid_session
+ post :create, {:order => { "member_id" => "invalid value" }}
response.should render_template("new")
end
end
@@ -88,18 +89,18 @@ describe OrdersController do
# receives the :update_attributes message with whatever params are
# submitted in the request.
Order.any_instance.should_receive(:update_attributes).with({ "member_id" => "MyString" })
- put :update, {:id => order.to_param, :order => { "member_id" => "MyString" }}, valid_session
+ put :update, {:id => order.to_param, :order => { "member_id" => "MyString" }}
end
it "assigns the requested order as @order" do
order = Order.create! valid_attributes
- put :update, {:id => order.to_param, :order => valid_attributes}, valid_session
+ put :update, {:id => order.to_param, :order => valid_attributes}
assigns(:order).should eq(order)
end
it "redirects to the order" do
order = Order.create! valid_attributes
- put :update, {:id => order.to_param, :order => valid_attributes}, valid_session
+ put :update, {:id => order.to_param, :order => valid_attributes}
response.should redirect_to(order)
end
end
@@ -109,7 +110,7 @@ describe OrdersController do
order = Order.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Order.any_instance.stub(:save).and_return(false)
- put :update, {:id => order.to_param, :order => { "member_id" => "invalid value" }}, valid_session
+ put :update, {:id => order.to_param, :order => { "member_id" => "invalid value" }}
assigns(:order).should eq(order)
end
@@ -117,7 +118,7 @@ describe OrdersController do
order = Order.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Order.any_instance.stub(:save).and_return(false)
- put :update, {:id => order.to_param, :order => { "member_id" => "invalid value" }}, valid_session
+ put :update, {:id => order.to_param, :order => { "member_id" => "invalid value" }}
response.should render_template("edit")
end
end
@@ -127,13 +128,13 @@ describe OrdersController do
it "destroys the requested order" do
order = Order.create! valid_attributes
expect {
- delete :destroy, {:id => order.to_param}, valid_session
+ delete :destroy, {:id => order.to_param}
}.to change(Order, :count).by(-1)
end
it "redirects to the orders list" do
order = Order.create! valid_attributes
- delete :destroy, {:id => order.to_param}, valid_session
+ delete :destroy, {:id => order.to_param}
response.should redirect_to(orders_url)
end
end
diff --git a/spec/controllers/products_controller_spec.rb b/spec/controllers/products_controller_spec.rb
index c31c2c9ae..13f77f195 100644
--- a/spec/controllers/products_controller_spec.rb
+++ b/spec/controllers/products_controller_spec.rb
@@ -2,6 +2,8 @@ require 'spec_helper'
describe ProductsController do
+ login_member(:admin_member)
+
def valid_attributes
{
:name => "product name",
@@ -17,7 +19,7 @@ describe ProductsController do
describe "GET index" do
it "assigns all products as @products" do
product = Product.create! valid_attributes
- get :index, {}, valid_session
+ get :index, {}
assigns(:products).should eq([product])
end
end
@@ -25,14 +27,14 @@ describe ProductsController do
describe "GET show" do
it "assigns the requested product as @product" do
product = Product.create! valid_attributes
- get :show, {:id => product.to_param}, valid_session
+ get :show, {:id => product.to_param}
assigns(:product).should eq(product)
end
end
describe "GET new" do
it "assigns a new product as @product" do
- get :new, {}, valid_session
+ get :new, {}
assigns(:product).should be_a_new(Product)
end
end
@@ -40,7 +42,7 @@ describe ProductsController do
describe "GET edit" do
it "assigns the requested product as @product" do
product = Product.create! valid_attributes
- get :edit, {:id => product.to_param}, valid_session
+ get :edit, {:id => product.to_param}
assigns(:product).should eq(product)
end
end
@@ -49,18 +51,18 @@ describe ProductsController do
describe "with valid params" do
it "creates a new Product" do
expect {
- post :create, {:product => valid_attributes}, valid_session
+ post :create, {:product => valid_attributes}
}.to change(Product, :count).by(1)
end
it "assigns a newly created product as @product" do
- post :create, {:product => valid_attributes}, valid_session
+ post :create, {:product => valid_attributes}
assigns(:product).should be_a(Product)
assigns(:product).should be_persisted
end
it "redirects to the created product" do
- post :create, {:product => valid_attributes}, valid_session
+ post :create, {:product => valid_attributes}
response.should redirect_to(Product.last)
end
end
@@ -69,14 +71,14 @@ describe ProductsController do
it "assigns a newly created but unsaved product as @product" do
# Trigger the behavior that occurs when invalid params are submitted
Product.any_instance.stub(:save).and_return(false)
- post :create, {:product => { "name" => "invalid value" }}, valid_session
+ post :create, {:product => { "name" => "invalid value" }}
assigns(:product).should be_a_new(Product)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Product.any_instance.stub(:save).and_return(false)
- post :create, {:product => { "name" => "invalid value" }}, valid_session
+ post :create, {:product => { "name" => "invalid value" }}
response.should render_template("new")
end
end
@@ -91,18 +93,18 @@ describe ProductsController do
# receives the :update_attributes message with whatever params are
# submitted in the request.
Product.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" })
- put :update, {:id => product.to_param, :product => { "name" => "MyString" }}, valid_session
+ put :update, {:id => product.to_param, :product => { "name" => "MyString" }}
end
it "assigns the requested product as @product" do
product = Product.create! valid_attributes
- put :update, {:id => product.to_param, :product => valid_attributes}, valid_session
+ put :update, {:id => product.to_param, :product => valid_attributes}
assigns(:product).should eq(product)
end
it "redirects to the product" do
product = Product.create! valid_attributes
- put :update, {:id => product.to_param, :product => valid_attributes}, valid_session
+ put :update, {:id => product.to_param, :product => valid_attributes}
response.should redirect_to(product)
end
end
@@ -112,7 +114,7 @@ describe ProductsController do
product = Product.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Product.any_instance.stub(:save).and_return(false)
- put :update, {:id => product.to_param, :product => { "name" => "invalid value" }}, valid_session
+ put :update, {:id => product.to_param, :product => { "name" => "invalid value" }}
assigns(:product).should eq(product)
end
@@ -120,7 +122,7 @@ describe ProductsController do
product = Product.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Product.any_instance.stub(:save).and_return(false)
- put :update, {:id => product.to_param, :product => { "name" => "invalid value" }}, valid_session
+ put :update, {:id => product.to_param, :product => { "name" => "invalid value" }}
response.should render_template("edit")
end
end
@@ -130,13 +132,13 @@ describe ProductsController do
it "destroys the requested product" do
product = Product.create! valid_attributes
expect {
- delete :destroy, {:id => product.to_param}, valid_session
+ delete :destroy, {:id => product.to_param}
}.to change(Product, :count).by(-1)
end
it "redirects to the products list" do
product = Product.create! valid_attributes
- delete :destroy, {:id => product.to_param}, valid_session
+ delete :destroy, {:id => product.to_param}
response.should redirect_to(products_url)
end
end
diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb
new file mode 100644
index 000000000..fad178cc6
--- /dev/null
+++ b/spec/controllers/shop_controller_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe ShopController do
+
+ before :each do
+ @product1 = FactoryGirl.create(:product)
+ @product2 = FactoryGirl.create(:product)
+ end
+
+ describe "GET index" do
+ it "assigns all products as @products" do
+ get :index, {}
+ assigns(:products).should eq([@product1, @product2])
+ end
+ end
+
+end
diff --git a/spec/requests/orders_spec.rb b/spec/requests/orders_spec.rb
deleted file mode 100644
index 0ab48154e..000000000
--- a/spec/requests/orders_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'spec_helper'
-
-describe "Orders" do
- describe "GET /orders" do
- it "works! (now write some real specs)" do
- # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
- get orders_path
- response.status.should be(200)
- end
- end
-end
diff --git a/spec/requests/products_spec.rb b/spec/requests/products_spec.rb
deleted file mode 100644
index 5618d7115..000000000
--- a/spec/requests/products_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'spec_helper'
-
-describe "Products" do
- describe "GET /products" do
- it "works! (now write some real specs)" do
- # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
- get products_path
- response.status.should be(200)
- end
- end
-end
diff --git a/spec/views/shop/index_spec.rb b/spec/views/shop/index_spec.rb
index c2f306fd7..d6dce7065 100644
--- a/spec/views/shop/index_spec.rb
+++ b/spec/views/shop/index_spec.rb
@@ -2,7 +2,18 @@ require 'spec_helper'
describe 'shop/index.html.haml', :type => "view" do
before(:each) do
+ @product1 = FactoryGirl.create(:product)
+ @product2 = FactoryGirl.create(:product)
+ assign(:products, [@product1, @product2])
render
end
+ it 'shows products' do
+ assert_select("h2", :text => @product1.name)
+ end
+
+ it 'shows prices in AUD' do
+ rendered.should contain '9.99 AUD'
+ end
+
end