From df5ee9cf4b4b131541cff326b4e793e2e53edc72 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 17 May 2013 15:11:55 +1000 Subject: [PATCH] give each member an account_detail entry --- app/models/member.rb | 2 ++ .../20130517015920_create_account_details.rb | 2 +- lib/tasks/growstuff.rake | 10 ++++++++ .../account_details_controller_spec.rb | 24 ------------------- spec/factories/account_details.rb | 2 +- spec/models/member_spec.rb | 5 ++++ .../account_details/edit.html.haml_spec.rb | 2 +- .../account_details/index.html.haml_spec.rb | 4 ++-- .../account_details/new.html.haml_spec.rb | 2 +- .../account_details/show.html.haml_spec.rb | 2 +- 10 files changed, 24 insertions(+), 31 deletions(-) diff --git a/app/models/member.rb b/app/models/member.rb index 618583293..d8766ea17 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -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) diff --git a/db/migrate/20130517015920_create_account_details.rb b/db/migrate/20130517015920_create_account_details.rb index 245091684..c4fc5baef 100644 --- a/db/migrate/20130517015920_create_account_details.rb +++ b/db/migrate/20130517015920_create_account_details.rb @@ -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 diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index fb87ea319..89f4b0e8f 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -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 diff --git a/spec/controllers/account_details_controller_spec.rb b/spec/controllers/account_details_controller_spec.rb index 9d5360ee6..896b282fe 100644 --- a/spec/controllers/account_details_controller_spec.rb +++ b/spec/controllers/account_details_controller_spec.rb @@ -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 diff --git a/spec/factories/account_details.rb b/spec/factories/account_details.rb index 3c8ad48ec..40e073679 100644 --- a/spec/factories/account_details.rb +++ b/spec/factories/account_details.rb @@ -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 diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 7037ce904..109a3bdcb 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -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 diff --git a/spec/views/account_details/edit.html.haml_spec.rb b/spec/views/account_details/edit.html.haml_spec.rb index 53d30247c..7b02196fe 100644 --- a/spec/views/account_details/edit.html.haml_spec.rb +++ b/spec/views/account_details/edit.html.haml_spec.rb @@ -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 diff --git a/spec/views/account_details/index.html.haml_spec.rb b/spec/views/account_details/index.html.haml_spec.rb index 69470a9d3..619f7ddf0 100644 --- a/spec/views/account_details/index.html.haml_spec.rb +++ b/spec/views/account_details/index.html.haml_spec.rb @@ -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 diff --git a/spec/views/account_details/new.html.haml_spec.rb b/spec/views/account_details/new.html.haml_spec.rb index 9c81cd855..a4ece5750 100644 --- a/spec/views/account_details/new.html.haml_spec.rb +++ b/spec/views/account_details/new.html.haml_spec.rb @@ -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 diff --git a/spec/views/account_details/show.html.haml_spec.rb b/spec/views/account_details/show.html.haml_spec.rb index 766326f6b..633dd6ee4 100644 --- a/spec/views/account_details/show.html.haml_spec.rb +++ b/spec/views/account_details/show.html.haml_spec.rb @@ -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