mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 16:58:35 -04:00
added account type and paid months columns to product
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
class AccountType < ActiveRecord::Base
|
||||
attr_accessible :is_paid, :is_permanent_paid, :name
|
||||
has_many :products
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class Product < ActiveRecord::Base
|
||||
attr_accessible :description, :min_price, :name
|
||||
attr_accessible :description, :min_price, :name,
|
||||
:account_type_id, :paid_months
|
||||
|
||||
has_and_belongs_to_many :orders
|
||||
belongs_to :account_type
|
||||
|
||||
def to_s
|
||||
name
|
||||
|
||||
@@ -15,5 +15,13 @@
|
||||
.field
|
||||
= f.label :min_price
|
||||
= f.text_field :min_price
|
||||
.field
|
||||
= f.label :account_type
|
||||
= collection_select(:product, :account_type_id, AccountType.all, :id,
|
||||
:name, :selected => @product.account_type_id )
|
||||
.field
|
||||
= f.label :paid_months
|
||||
= f.text_field :paid_months
|
||||
.control-group
|
||||
.actions
|
||||
= f.submit 'Save'
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
%th Name
|
||||
%th Description
|
||||
%th Min price
|
||||
%th Account type
|
||||
%th Paid months
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
@@ -14,6 +16,8 @@
|
||||
%td= product.name
|
||||
%td= product.description
|
||||
%td= product.min_price
|
||||
%td= product.account_type ? product.account_type.name : ""
|
||||
%td= product.paid_months
|
||||
%td= link_to 'Show', product
|
||||
%td= link_to 'Edit', edit_product_path(product)
|
||||
%td= link_to 'Destroy', product, :method => :delete, :data => { :confirm => 'Are you sure?' }
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
%p
|
||||
%b Min price:
|
||||
= @product.min_price
|
||||
%p
|
||||
%b Account type:
|
||||
= @product.account_type.name
|
||||
%p
|
||||
%b Paid months:
|
||||
= @product.paid_months
|
||||
|
||||
= link_to 'Edit', edit_product_path(@product)
|
||||
\|
|
||||
|
||||
6
db/migrate/20130518000339_add_columns_to_product.rb
Normal file
6
db/migrate/20130518000339_add_columns_to_product.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddColumnsToProduct < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :products, :account_type_id, :integer
|
||||
add_column :products, :paid_months, :integer
|
||||
end
|
||||
end
|
||||
14
db/schema.rb
14
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130517234458) do
|
||||
ActiveRecord::Schema.define(:version => 20130518000339) do
|
||||
|
||||
create_table "account_details", :force => true do |t|
|
||||
t.integer "member_id", :null => false
|
||||
@@ -185,11 +185,13 @@ ActiveRecord::Schema.define(:version => 20130517234458) do
|
||||
add_index "posts", ["slug"], :name => "index_updates_on_slug", :unique => true
|
||||
|
||||
create_table "products", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.string "description", :null => false
|
||||
t.integer "min_price", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "name", :null => false
|
||||
t.string "description", :null => false
|
||||
t.integer "min_price", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "account_type_id"
|
||||
t.integer "paid_months"
|
||||
end
|
||||
|
||||
create_table "roles", :force => true do |t|
|
||||
|
||||
13
db/seeds.rb
13
db/seeds.rb
@@ -64,12 +64,12 @@ if Rails.env.development? or Rails.env.test?
|
||||
:is_paid => false,
|
||||
:is_permanent_paid => false
|
||||
)
|
||||
AccountType.create!(
|
||||
@paid_account = AccountType.create!(
|
||||
:name => "Paid",
|
||||
:is_paid => true,
|
||||
:is_permanent_paid => false
|
||||
)
|
||||
AccountType.create!(
|
||||
@seed_account = AccountType.create!(
|
||||
:name => "Seed",
|
||||
:is_paid => true,
|
||||
:is_permanent_paid => true
|
||||
@@ -83,13 +83,16 @@ if Rails.env.development? or Rails.env.test?
|
||||
puts "Adding products..."
|
||||
Product.create!(
|
||||
:name => "Annual subscription",
|
||||
:description => "Paid account, renews yearly",
|
||||
:min_price => 3000
|
||||
:description => "Paid account, 1 year",
|
||||
:min_price => 3000,
|
||||
:account_type_id => @paid_account.id,
|
||||
:paid_months => 12
|
||||
)
|
||||
Product.create!(
|
||||
:name => "Seed account",
|
||||
:description => "Paid account, in perpetuity",
|
||||
:min_price => 15000
|
||||
:min_price => 15000,
|
||||
:account_type_id => @seed_account.id,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -5,5 +5,7 @@ FactoryGirl.define do
|
||||
name "annual subscription"
|
||||
description "paid membership, renewing yearly"
|
||||
min_price "999"
|
||||
account_type
|
||||
paid_months 12
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "AccountTypes" do
|
||||
describe "GET /account_types" 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 account_types_path
|
||||
response.status.should be(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -17,6 +17,8 @@ describe "products/new" do
|
||||
assert_select "input#product_name", :name => "product[name]"
|
||||
assert_select "input#product_description", :name => "product[description]"
|
||||
assert_select "input#product_min_price", :name => "product[min_price]"
|
||||
assert_select "select#product_account_type_id", :name => "product[account_type_id]"
|
||||
assert_select "input#product_paid_months", :name => "product[paid_months]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user