give each member an account_detail entry

This commit is contained in:
Skud
2013-05-17 15:11:55 +10:00
parent 0157229936
commit df5ee9cf4b
10 changed files with 24 additions and 31 deletions

View File

@@ -68,6 +68,8 @@ class Member < ActiveRecord::Base
# Give each new member a default garden
after_create {|member| Garden.create(:name => "Garden", :owner_id => member.id) }
# and an account details record
after_create {|member| AccountDetail.create(:member_id => member.id) }
# allow login via either login_name or email address
def self.find_first_by_auth_conditions(warden_conditions)

View File

@@ -2,7 +2,7 @@ class CreateAccountDetails < ActiveRecord::Migration
def change
create_table :account_details do |t|
t.integer :member_id, :null => false
t.string :account_type, :null => false, :default => 'free'
t.integer :account_type
t.datetime :paid_until
t.timestamps

View File

@@ -40,6 +40,16 @@ namespace :growstuff do
end
end
task :account_details => :environment do
desc "Give each member an account_detail record"
Member.all.each do |m|
unless m.account_detail
AccountDetail.create(:member_id => m.id)
end
end
end
end
end

View File

@@ -1,35 +1,11 @@
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe AccountDetailsController do
# This should return the minimal set of attributes required to create a valid
# AccountDetail. As you add validations to AccountDetail, be sure to
# update the return value of this method accordingly.
def valid_attributes
{ "member_id" => "1" }
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# AccountDetailsController. Be sure to keep this updated too.
def valid_session
{}
end

View File

@@ -3,7 +3,7 @@
FactoryGirl.define do
factory :account_detail do
member_id 1
account_type "MyString"
account_type 1
paid_until "2013-05-17 11:59:20"
end
end

View File

@@ -29,6 +29,11 @@ describe 'member' do
@member.gardens.count.should == 1
end
it 'should have a account detail entry' do
@member.save
@member.account_detail.should be_an_instance_of AccountDetail
end
it "doesn't show email by default" do
@member.save
@member.show_email.should be_false

View File

@@ -4,7 +4,7 @@ describe "account_details/edit" do
before(:each) do
@account_detail = assign(:account_detail, stub_model(AccountDetail,
:member_id => 1,
:account_type => "MyString"
:account_type => 1
))
end

View File

@@ -5,11 +5,11 @@ describe "account_details/index" do
assign(:account_details, [
stub_model(AccountDetail,
:member_id => 1,
:account_type => "Account Type"
:account_type => 1
),
stub_model(AccountDetail,
:member_id => 1,
:account_type => "Account Type"
:account_type => 1
)
])
end

View File

@@ -4,7 +4,7 @@ describe "account_details/new" do
before(:each) do
assign(:account_detail, stub_model(AccountDetail,
:member_id => 1,
:account_type => "MyString"
:account_type => 1
).as_new_record)
end

View File

@@ -4,7 +4,7 @@ describe "account_details/show" do
before(:each) do
@account_detail = assign(:account_detail, stub_model(AccountDetail,
:member_id => 1,
:account_type => "Account Type"
:account_type => 1
))
end