From 3aaf344951fc5be91628212d784e798f6502d476 Mon Sep 17 00:00:00 2001 From: Skud Date: Sat, 18 May 2013 10:50:36 +1000 Subject: [PATCH] rename account details to just account --- .../javascripts/account_details.js.coffee | 3 - app/controllers/account_details_controller.rb | 46 ---------- app/controllers/accounts_controller.rb | 46 ++++++++++ app/helpers/account_details_helper.rb | 2 - app/models/ability.rb | 6 +- app/models/{account_detail.rb => account.rb} | 2 +- app/models/member.rb | 6 +- app/views/account_details/edit.html.haml | 7 -- app/views/account_details/index.html.haml | 23 ----- app/views/account_details/new.html.haml | 5 - app/views/account_details/show.html.haml | 18 ---- .../_form.html.haml | 8 +- app/views/accounts/edit.html.haml | 7 ++ app/views/accounts/index.html.haml | 23 +++++ app/views/accounts/new.html.haml | 5 + app/views/accounts/show.html.haml | 18 ++++ config/routes.rb | 14 +-- ...002942_rename_account_detail_to_account.rb | 6 ++ db/schema.rb | 18 ++-- .../account_details_controller_spec.rb | 91 ------------------- spec/controllers/accounts_controller_spec.rb | 91 +++++++++++++++++++ .../{account_details.rb => accounts.rb} | 0 spec/helpers/account_details_helper_spec.rb | 15 --- spec/models/ability_spec.rb | 18 ++-- ...account_detail_spec.rb => account_spec.rb} | 6 +- spec/models/member_spec.rb | 4 +- spec/routing/account_details_routing_spec.rb | 35 ------- .../account_details/edit.html.haml_spec.rb | 18 ---- .../account_details/index.html.haml_spec.rb | 15 --- .../account_details/new.html.haml_spec.rb | 18 ---- spec/views/accounts/edit.html.haml_spec.rb | 18 ++++ spec/views/accounts/index.html.haml_spec.rb | 15 +++ spec/views/accounts/new.html.haml_spec.rb | 18 ++++ .../show.html.haml_spec.rb | 8 +- 34 files changed, 290 insertions(+), 343 deletions(-) delete mode 100644 app/assets/javascripts/account_details.js.coffee delete mode 100644 app/controllers/account_details_controller.rb create mode 100644 app/controllers/accounts_controller.rb delete mode 100644 app/helpers/account_details_helper.rb rename app/models/{account_detail.rb => account.rb} (84%) delete mode 100644 app/views/account_details/edit.html.haml delete mode 100644 app/views/account_details/index.html.haml delete mode 100644 app/views/account_details/new.html.haml delete mode 100644 app/views/account_details/show.html.haml rename app/views/{account_details => accounts}/_form.html.haml (54%) create mode 100644 app/views/accounts/edit.html.haml create mode 100644 app/views/accounts/index.html.haml create mode 100644 app/views/accounts/new.html.haml create mode 100644 app/views/accounts/show.html.haml create mode 100644 db/migrate/20130518002942_rename_account_detail_to_account.rb delete mode 100644 spec/controllers/account_details_controller_spec.rb create mode 100644 spec/controllers/accounts_controller_spec.rb rename spec/factories/{account_details.rb => accounts.rb} (100%) delete mode 100644 spec/helpers/account_details_helper_spec.rb rename spec/models/{account_detail_spec.rb => account_spec.rb} (65%) delete mode 100644 spec/routing/account_details_routing_spec.rb delete mode 100644 spec/views/account_details/edit.html.haml_spec.rb delete mode 100644 spec/views/account_details/index.html.haml_spec.rb delete mode 100644 spec/views/account_details/new.html.haml_spec.rb create mode 100644 spec/views/accounts/edit.html.haml_spec.rb create mode 100644 spec/views/accounts/index.html.haml_spec.rb create mode 100644 spec/views/accounts/new.html.haml_spec.rb rename spec/views/{account_details => accounts}/show.html.haml_spec.rb (55%) diff --git a/app/assets/javascripts/account_details.js.coffee b/app/assets/javascripts/account_details.js.coffee deleted file mode 100644 index 761567942..000000000 --- a/app/assets/javascripts/account_details.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/controllers/account_details_controller.rb b/app/controllers/account_details_controller.rb deleted file mode 100644 index 364b5bee4..000000000 --- a/app/controllers/account_details_controller.rb +++ /dev/null @@ -1,46 +0,0 @@ -class AccountDetailsController < ApplicationController - load_and_authorize_resource - # GET /account_details - # GET /account_details.json - def index - @account_details = AccountDetail.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @account_details } - end - end - - # GET /account_details/1 - # GET /account_details/1.json - def show - @account_detail = AccountDetail.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @account_detail } - end - end - - # GET /account_details/1/edit - def edit - @account_detail = AccountDetail.find(params[:id]) - end - - # PUT /account_details/1 - # PUT /account_details/1.json - def update - @account_detail = AccountDetail.find(params[:id]) - - respond_to do |format| - if @account_detail.update_attributes(params[:account_detail]) - format.html { redirect_to @account_detail, notice: 'Account detail was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: "edit" } - format.json { render json: @account_detail.errors, status: :unprocessable_entity } - end - end - end - -end diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb new file mode 100644 index 000000000..b3f7f606a --- /dev/null +++ b/app/controllers/accounts_controller.rb @@ -0,0 +1,46 @@ +class AccountsController < ApplicationController + load_and_authorize_resource + # GET /accounts + # GET /accounts.json + def index + @accounts = Account.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @accounts } + end + end + + # GET /accounts/1 + # GET /accounts/1.json + def show + @account = Account.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @account } + end + end + + # GET /accounts/1/edit + def edit + @account = Account.find(params[:id]) + end + + # PUT /accounts/1 + # PUT /accounts/1.json + def update + @account = Account.find(params[:id]) + + respond_to do |format| + if @account.update_attributes(params[:account]) + format.html { redirect_to @account, notice: 'Account detail was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @account.errors, status: :unprocessable_entity } + end + end + end + +end diff --git a/app/helpers/account_details_helper.rb b/app/helpers/account_details_helper.rb deleted file mode 100644 index ea418e8ec..000000000 --- a/app/helpers/account_details_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AccountDetailsHelper -end diff --git a/app/models/ability.rb b/app/models/ability.rb index 0d6da1bd7..c3c59ee4d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -16,7 +16,7 @@ class Ability # and nobody should be able to view this except admins cannot :read, Role cannot :read, Product - cannot :read, AccountDetail + cannot :read, Account cannot :read, AccountType if member @@ -98,8 +98,8 @@ class Ability # admins can read and manage members' account details (paid acct # status, etc) - can :read, AccountDetail - can :manage, AccountDetail + can :read, Account + can :manage, Account can :read, AccountType can :manage, AccountType end diff --git a/app/models/account_detail.rb b/app/models/account.rb similarity index 84% rename from app/models/account_detail.rb rename to app/models/account.rb index c218a1c1f..25cfc05ba 100644 --- a/app/models/account_detail.rb +++ b/app/models/account.rb @@ -1,4 +1,4 @@ -class AccountDetail < ActiveRecord::Base +class Account < ActiveRecord::Base attr_accessible :account_type_id, :member_id, :paid_until belongs_to :member belongs_to :account_type diff --git a/app/models/member.rb b/app/models/member.rb index d8aa8e96c..6f6686c90 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -12,7 +12,7 @@ class Member < ActiveRecord::Base has_many :sent_notifications, :foreign_key => 'sender_id' has_many :authentications has_many :orders - has_one :account_detail + has_one :account default_scope order("lower(login_name) asc") scope :confirmed, where('confirmed_at IS NOT NULL') @@ -69,10 +69,10 @@ 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 + # and an account record (for paid accounts etc) # we use find_or_create to avoid accidentally creating a second one, # which can happen sometimes especially with FactoryGirl associations - after_create {|member| AccountDetail.find_or_create_by_member_id(:member_id => member.id) } + after_create {|member| Account.find_or_create_by_member_id(: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/app/views/account_details/edit.html.haml b/app/views/account_details/edit.html.haml deleted file mode 100644 index 4cca4b860..000000000 --- a/app/views/account_details/edit.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1 Editing account_detail - -= render 'form' - -= link_to 'Show', @account_detail -\| -= link_to 'Back', account_details_path diff --git a/app/views/account_details/index.html.haml b/app/views/account_details/index.html.haml deleted file mode 100644 index 839dbafd3..000000000 --- a/app/views/account_details/index.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -%h1 Listing account_details - -%table - %tr - %th Member - %th Account type - %th Paid until - %th - %th - %th - - - @account_details.each do |account_detail| - %tr - %td= account_detail.member_id - %td= account_detail.account_type - %td= account_detail.paid_until - %td= link_to 'Show', account_detail - %td= link_to 'Edit', edit_account_detail_path(account_detail) - %td= link_to 'Destroy', account_detail, :method => :delete, :data => { :confirm => 'Are you sure?' } - -%br - -= link_to 'New Account detail', new_account_detail_path diff --git a/app/views/account_details/new.html.haml b/app/views/account_details/new.html.haml deleted file mode 100644 index c9e8e4c4f..000000000 --- a/app/views/account_details/new.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%h1 New account_detail - -= render 'form' - -= link_to 'Back', account_details_path diff --git a/app/views/account_details/show.html.haml b/app/views/account_details/show.html.haml deleted file mode 100644 index e9d97aa4e..000000000 --- a/app/views/account_details/show.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -%p#notice= notice - -%p - %b Member: - = @account_detail.member_id -%p - %b Account type: - - if @account_detail.account_type - = @account_detail.account_type.name - - else - Free account -%p - %b Paid until: - = @account_detail.paid_until - -= link_to 'Edit', edit_account_detail_path(@account_detail) -\| -= link_to 'Back', account_details_path diff --git a/app/views/account_details/_form.html.haml b/app/views/accounts/_form.html.haml similarity index 54% rename from app/views/account_details/_form.html.haml rename to app/views/accounts/_form.html.haml index 034828629..6e648d622 100644 --- a/app/views/account_details/_form.html.haml +++ b/app/views/accounts/_form.html.haml @@ -1,9 +1,9 @@ -= form_for @account_detail do |f| - - if @account_detail.errors.any? += form_for @account do |f| + - if @account.errors.any? #error_explanation - %h2= "#{pluralize(@account_detail.errors.count, "error")} prohibited this account_detail from being saved:" + %h2= "#{pluralize(@account.errors.count, "error")} prohibited this account from being saved:" %ul - - @account_detail.errors.full_messages.each do |msg| + - @account.errors.full_messages.each do |msg| %li= msg .field diff --git a/app/views/accounts/edit.html.haml b/app/views/accounts/edit.html.haml new file mode 100644 index 000000000..5b4039cfa --- /dev/null +++ b/app/views/accounts/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing account + += render 'form' + += link_to 'Show', @account +\| += link_to 'Back', accounts_path diff --git a/app/views/accounts/index.html.haml b/app/views/accounts/index.html.haml new file mode 100644 index 000000000..66345747f --- /dev/null +++ b/app/views/accounts/index.html.haml @@ -0,0 +1,23 @@ +%h1 Listing accounts + +%table + %tr + %th Member + %th Account type + %th Paid until + %th + %th + %th + + - @accounts.each do |account| + %tr + %td= account.member_id + %td= account.account_type + %td= account.paid_until + %td= link_to 'Show', account + %td= link_to 'Edit', edit_account_path(account) + %td= link_to 'Destroy', account, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Account detail', new_account_path diff --git a/app/views/accounts/new.html.haml b/app/views/accounts/new.html.haml new file mode 100644 index 000000000..489317b27 --- /dev/null +++ b/app/views/accounts/new.html.haml @@ -0,0 +1,5 @@ +%h1 New account + += render 'form' + += link_to 'Back', accounts_path diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml new file mode 100644 index 000000000..8a9b0e639 --- /dev/null +++ b/app/views/accounts/show.html.haml @@ -0,0 +1,18 @@ +%p#notice= notice + +%p + %b Member: + = @account.member_id +%p + %b Account type: + - if @account.account_type + = @account.account_type.name + - else + Free account +%p + %b Paid until: + = @account.paid_until + += link_to 'Edit', edit_account_path(@account) +\| += link_to 'Back', accounts_path diff --git a/config/routes.rb b/config/routes.rb index 1d6ab4adc..6064228c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,5 @@ Growstuff::Application.routes.draw do - resources :account_types - - - resources :account_details - - - resources :order_items - - devise_for :members, :controllers => { :registrations => "registrations" } resources :authentications @@ -22,8 +13,13 @@ Growstuff::Application.routes.draw do resources :roles resources :forums resources :notifications + + # everything for paid accounts etc + resources :account_types + resources :accounts resources :orders match 'orders/:id/complete' => 'orders#complete', :as => 'complete_order' + resources :order_items resources :products get "home/index" diff --git a/db/migrate/20130518002942_rename_account_detail_to_account.rb b/db/migrate/20130518002942_rename_account_detail_to_account.rb new file mode 100644 index 000000000..8c2243431 --- /dev/null +++ b/db/migrate/20130518002942_rename_account_detail_to_account.rb @@ -0,0 +1,6 @@ +class RenameAccountDetailToAccount < ActiveRecord::Migration + def change + rename_table :account_details, :accounts + end + +end diff --git a/db/schema.rb b/db/schema.rb index e2447b6b6..7a372a776 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,15 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130518000339) do - - create_table "account_details", :force => true do |t| - t.integer "member_id", :null => false - t.integer "account_type_id" - t.datetime "paid_until" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end +ActiveRecord::Schema.define(:version => 20130518002942) do create_table "account_types", :force => true do |t| t.string "name", :null => false @@ -29,6 +21,14 @@ ActiveRecord::Schema.define(:version => 20130518000339) do t.datetime "updated_at", :null => false end + create_table "accounts", :force => true do |t| + t.integer "member_id", :null => false + t.integer "account_type_id" + t.datetime "paid_until" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "authentications", :force => true do |t| t.integer "member_id", :null => false t.string "provider", :null => false diff --git a/spec/controllers/account_details_controller_spec.rb b/spec/controllers/account_details_controller_spec.rb deleted file mode 100644 index ad0bcef48..000000000 --- a/spec/controllers/account_details_controller_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -require 'spec_helper' - -describe AccountDetailsController do - - login_member(:admin_member) - - def valid_attributes - { "paid_until" => Time.now } - end - - def create_account_detail - # account details are automatically created when you create a new - # member; creating them manually will just cause errors as only one is - # allowed. - - member = FactoryGirl.create(:member) - return member.account_detail - end - - describe "GET index" do - it "assigns all account_details as @account_details" do - account_detail = create_account_detail - get :index, {} - # can't match the whole list because it includes the one for the - # logged in admin member, sigh - assigns(:account_details).should include(account_detail) - assigns(:account_details).count.should eq 2 - end - end - - describe "GET show" do - it "assigns the requested account_detail as @account_detail" do - account_detail = create_account_detail - get :show, {:id => account_detail.to_param} - assigns(:account_detail).should eq(account_detail) - end - end - - describe "GET edit" do - it "assigns the requested account_detail as @account_detail" do - account_detail = create_account_detail - get :edit, {:id => account_detail.to_param} - assigns(:account_detail).should eq(account_detail) - end - end - - describe "PUT update" do - describe "with valid params" do - it "updates the requested account_detail" do - account_detail = create_account_detail - # Assuming there are no other account_detail in the database, this - # specifies that the AccountDetail created on the previous line - # receives the :update_attributes message with whatever params are - # submitted in the request. - AccountDetail.any_instance.should_receive(:update_attributes).with({ "member_id" => "1" }) - put :update, {:id => account_detail.to_param, :account_detail => { "member_id" => "1" }} - end - - it "assigns the requested account_detail as @account_detail" do - account_detail = create_account_detail - put :update, {:id => account_detail.to_param, :account_detail => valid_attributes} - assigns(:account_detail).should eq(account_detail) - end - - it "redirects to the account_detail" do - account_detail = create_account_detail - put :update, {:id => account_detail.to_param, :account_detail => valid_attributes} - response.should redirect_to(account_detail) - end - end - - describe "with invalid params" do - it "assigns the account_detail as @account_detail" do - account_detail = create_account_detail - # Trigger the behavior that occurs when invalid params are submitted - AccountDetail.any_instance.stub(:save).and_return(false) - put :update, {:id => account_detail.to_param, :account_detail => { "member_id" => "invalid value" }} - assigns(:account_detail).should eq(account_detail) - end - - it "re-renders the 'edit' template" do - account_detail = create_account_detail - # Trigger the behavior that occurs when invalid params are submitted - AccountDetail.any_instance.stub(:save).and_return(false) - put :update, {:id => account_detail.to_param, :account_detail => { "member_id" => "invalid value" }} - response.should render_template("edit") - end - end - end - -end diff --git a/spec/controllers/accounts_controller_spec.rb b/spec/controllers/accounts_controller_spec.rb new file mode 100644 index 000000000..f04a8cc69 --- /dev/null +++ b/spec/controllers/accounts_controller_spec.rb @@ -0,0 +1,91 @@ +require 'spec_helper' + +describe AccountsController do + + login_member(:admin_member) + + def valid_attributes + { "paid_until" => Time.now } + end + + def create_account + # account details are automatically created when you create a new + # member; creating them manually will just cause errors as only one is + # allowed. + + member = FactoryGirl.create(:member) + return member.account + end + + describe "GET index" do + it "assigns all accounts as @accounts" do + account = create_account + get :index, {} + # can't match the whole list because it includes the one for the + # logged in admin member, sigh + assigns(:accounts).should include(account) + assigns(:accounts).count.should eq 2 + end + end + + describe "GET show" do + it "assigns the requested account as @account" do + account = create_account + get :show, {:id => account.to_param} + assigns(:account).should eq(account) + end + end + + describe "GET edit" do + it "assigns the requested account as @account" do + account = create_account + get :edit, {:id => account.to_param} + assigns(:account).should eq(account) + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested account" do + account = create_account + # Assuming there are no other account in the database, this + # specifies that the Account created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Account.any_instance.should_receive(:update_attributes).with({ "member_id" => "1" }) + put :update, {:id => account.to_param, :account => { "member_id" => "1" }} + end + + it "assigns the requested account as @account" do + account = create_account + put :update, {:id => account.to_param, :account => valid_attributes} + assigns(:account).should eq(account) + end + + it "redirects to the account" do + account = create_account + put :update, {:id => account.to_param, :account => valid_attributes} + response.should redirect_to(account) + end + end + + describe "with invalid params" do + it "assigns the account as @account" do + account = create_account + # Trigger the behavior that occurs when invalid params are submitted + Account.any_instance.stub(:save).and_return(false) + put :update, {:id => account.to_param, :account => { "member_id" => "invalid value" }} + assigns(:account).should eq(account) + end + + it "re-renders the 'edit' template" do + account = create_account + # Trigger the behavior that occurs when invalid params are submitted + Account.any_instance.stub(:save).and_return(false) + put :update, {:id => account.to_param, :account => { "member_id" => "invalid value" }} + response.should render_template("edit") + end + end + end + +end diff --git a/spec/factories/account_details.rb b/spec/factories/accounts.rb similarity index 100% rename from spec/factories/account_details.rb rename to spec/factories/accounts.rb diff --git a/spec/helpers/account_details_helper_spec.rb b/spec/helpers/account_details_helper_spec.rb deleted file mode 100644 index 4830dd76b..000000000 --- a/spec/helpers/account_details_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the AccountDetailsHelper. For example: -# -# describe AccountDetailsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe AccountDetailsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 722b52274..3d0cd04e3 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -246,17 +246,17 @@ describe Ability do context 'account details' do before(:each) do - @account_detail = @member.account_detail + @account = @member.account end context 'ordinary member' do it "can't read account details" do - @ability.should_not be_able_to(:read, @account_detail) + @ability.should_not be_able_to(:read, @account) end it "can't manage account details" do - @ability.should_not be_able_to(:create, AccountDetail) - @ability.should_not be_able_to(:update, @account_detail) - @ability.should_not be_able_to(:destroy, @account_detail) + @ability.should_not be_able_to(:create, Account) + @ability.should_not be_able_to(:update, @account) + @ability.should_not be_able_to(:destroy, @account) end end @@ -269,12 +269,12 @@ describe Ability do end it "can read account details" do - @admin_ability.should be_able_to(:read, @account_detail) + @admin_ability.should be_able_to(:read, @account) end it "can manage account details" do - @admin_ability.should be_able_to(:create, AccountDetail) - @admin_ability.should be_able_to(:update, @account_detail) - @admin_ability.should be_able_to(:destroy, @account_detail) + @admin_ability.should be_able_to(:create, Account) + @admin_ability.should be_able_to(:update, @account) + @admin_ability.should be_able_to(:destroy, @account) end end diff --git a/spec/models/account_detail_spec.rb b/spec/models/account_spec.rb similarity index 65% rename from spec/models/account_detail_spec.rb rename to spec/models/account_spec.rb index 94a786cd6..26d59116e 100644 --- a/spec/models/account_detail_spec.rb +++ b/spec/models/account_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -describe AccountDetail do +describe Account do before(:each) do @member = FactoryGirl.create(:member) end it "auto-creates an account detail record when a member is created" do - @member.account_detail.should be_an_instance_of AccountDetail + @member.account.should be_an_instance_of Account end it "won't let you create two account details for the same member" do - @details = AccountDetail.new(:member_id => @member.id) + @details = Account.new(:member_id => @member.id) @details.should_not be_valid end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 109a3bdcb..24c1badc2 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -29,9 +29,9 @@ describe 'member' do @member.gardens.count.should == 1 end - it 'should have a account detail entry' do + it 'should have a accounts entry' do @member.save - @member.account_detail.should be_an_instance_of AccountDetail + @member.account.should be_an_instance_of Account end it "doesn't show email by default" do diff --git a/spec/routing/account_details_routing_spec.rb b/spec/routing/account_details_routing_spec.rb deleted file mode 100644 index 538fa8ddf..000000000 --- a/spec/routing/account_details_routing_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "spec_helper" - -describe AccountDetailsController do - describe "routing" do - - it "routes to #index" do - get("/account_details").should route_to("account_details#index") - end - - it "routes to #new" do - get("/account_details/new").should route_to("account_details#new") - end - - it "routes to #show" do - get("/account_details/1").should route_to("account_details#show", :id => "1") - end - - it "routes to #edit" do - get("/account_details/1/edit").should route_to("account_details#edit", :id => "1") - end - - it "routes to #create" do - post("/account_details").should route_to("account_details#create") - end - - it "routes to #update" do - put("/account_details/1").should route_to("account_details#update", :id => "1") - end - - it "routes to #destroy" do - delete("/account_details/1").should route_to("account_details#destroy", :id => "1") - end - - end -end diff --git a/spec/views/account_details/edit.html.haml_spec.rb b/spec/views/account_details/edit.html.haml_spec.rb deleted file mode 100644 index df62bbac2..000000000 --- a/spec/views/account_details/edit.html.haml_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -describe "account_details/edit" do - before(:each) do - @member = FactoryGirl.create(:member) - @account_detail = assign(:account_detail, @member.account_detail) - end - - it "renders the edit account_detail form" do - render - - # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form", :action => account_details_path(@account_detail), :method => "post" do - assert_select "input#account_detail_member_id", :name => "account_detail[member_id]" - assert_select "input#account_detail_account_type", :name => "account_detail[account_type]" - end - end -end diff --git a/spec/views/account_details/index.html.haml_spec.rb b/spec/views/account_details/index.html.haml_spec.rb deleted file mode 100644 index c2561eed8..000000000 --- a/spec/views/account_details/index.html.haml_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe "account_details/index" do - before(:each) do - @member = FactoryGirl.create(:member) - @account_detail = @member.account_detail - assign(:account_details, [@account_detail, @account_detail]) - end - - it "renders a list of account_details" do - render - # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "tr>td", :text => @account_detail.member_id.to_s, :count => 2 - end -end diff --git a/spec/views/account_details/new.html.haml_spec.rb b/spec/views/account_details/new.html.haml_spec.rb deleted file mode 100644 index 05900eafe..000000000 --- a/spec/views/account_details/new.html.haml_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -describe "account_details/new" do - before(:each) do - @member = FactoryGirl.create(:member) - assign(:account_detail, @member.account_detail) - end - - it "renders new account_detail form" do - render - - # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form", :action => account_details_path, :method => "post" do - assert_select "input#account_detail_member_id", :name => "account_detail[member_id]" - assert_select "input#account_detail_account_type", :name => "account_detail[account_type]" - end - end -end diff --git a/spec/views/accounts/edit.html.haml_spec.rb b/spec/views/accounts/edit.html.haml_spec.rb new file mode 100644 index 000000000..af3931dfa --- /dev/null +++ b/spec/views/accounts/edit.html.haml_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe "accounts/edit" do + before(:each) do + @member = FactoryGirl.create(:member) + @account = assign(:account, @member.account) + end + + it "renders the edit account form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => accounts_path(@account), :method => "post" do + assert_select "input#account_member_id", :name => "account[member_id]" + assert_select "input#account_account_type", :name => "account[account_type]" + end + end +end diff --git a/spec/views/accounts/index.html.haml_spec.rb b/spec/views/accounts/index.html.haml_spec.rb new file mode 100644 index 000000000..56e76b0ff --- /dev/null +++ b/spec/views/accounts/index.html.haml_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "accounts/index" do + before(:each) do + @member = FactoryGirl.create(:member) + @account = @member.account + assign(:accounts, [@account, @account]) + end + + it "renders a list of accounts" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => @account.member_id.to_s, :count => 2 + end +end diff --git a/spec/views/accounts/new.html.haml_spec.rb b/spec/views/accounts/new.html.haml_spec.rb new file mode 100644 index 000000000..ab60cc346 --- /dev/null +++ b/spec/views/accounts/new.html.haml_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe "accounts/new" do + before(:each) do + @member = FactoryGirl.create(:member) + assign(:account, @member.account) + end + + it "renders new account form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => accounts_path, :method => "post" do + assert_select "input#account_member_id", :name => "account[member_id]" + assert_select "input#account_account_type", :name => "account[account_type]" + end + end +end diff --git a/spec/views/account_details/show.html.haml_spec.rb b/spec/views/accounts/show.html.haml_spec.rb similarity index 55% rename from spec/views/account_details/show.html.haml_spec.rb rename to spec/views/accounts/show.html.haml_spec.rb index e510602b8..cd8c0bd60 100644 --- a/spec/views/account_details/show.html.haml_spec.rb +++ b/spec/views/accounts/show.html.haml_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -describe "account_details/show" do +describe "accounts/show" do before(:each) do @member = FactoryGirl.create(:member) - @account_detail = assign(:account_detail, @member.account_detail) + @account = assign(:account, @member.account) end it "renders attributes in

" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - rendered.should contain @account_detail.member_id.to_s + rendered.should contain @account.member_id.to_s rendered.should contain 'Free account' - rendered.should contain @account_detail.paid_until.to_s + rendered.should contain @account.paid_until.to_s end end