From c595b2181dea5068e630851dadf03882cd5ef15c Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 17 May 2013 16:07:46 +1000 Subject: [PATCH] added account_types, fixed a bunch of tests --- .../javascripts/account_types.js.coffee | 3 + app/controllers/account_types_controller.rb | 83 +++++++++ app/helpers/account_types_helper.rb | 2 + app/models/account_detail.rb | 3 +- app/models/account_type.rb | 3 + app/views/account_details/show.html.haml | 2 +- app/views/account_types/_form.html.haml | 19 ++ app/views/account_types/edit.html.haml | 7 + app/views/account_types/index.html.haml | 23 +++ app/views/account_types/new.html.haml | 5 + app/views/account_types/show.html.haml | 15 ++ config/routes.rb | 3 + .../20130517015920_create_account_details.rb | 2 +- .../20130517051922_create_account_types.rb | 11 ++ db/schema.rb | 18 +- .../account_types_controller_spec.rb | 164 ++++++++++++++++++ spec/factories/account_details.rb | 4 +- spec/factories/account_types.rb | 9 + spec/helpers/account_types_helper_spec.rb | 15 ++ spec/models/account_type_spec.rb | 5 + spec/requests/account_types_spec.rb | 11 ++ spec/routing/account_types_routing_spec.rb | 35 ++++ .../account_details/edit.html.haml_spec.rb | 7 +- .../account_details/index.html.haml_spec.rb | 15 +- .../account_details/new.html.haml_spec.rb | 5 +- .../account_details/show.html.haml_spec.rb | 12 +- .../account_types/edit.html.haml_spec.rb | 22 +++ .../account_types/index.html.haml_spec.rb | 14 ++ .../views/account_types/new.html.haml_spec.rb | 22 +++ .../account_types/show.html.haml_spec.rb | 19 ++ 30 files changed, 522 insertions(+), 36 deletions(-) create mode 100644 app/assets/javascripts/account_types.js.coffee create mode 100644 app/controllers/account_types_controller.rb create mode 100644 app/helpers/account_types_helper.rb create mode 100644 app/models/account_type.rb create mode 100644 app/views/account_types/_form.html.haml create mode 100644 app/views/account_types/edit.html.haml create mode 100644 app/views/account_types/index.html.haml create mode 100644 app/views/account_types/new.html.haml create mode 100644 app/views/account_types/show.html.haml create mode 100644 db/migrate/20130517051922_create_account_types.rb create mode 100644 spec/controllers/account_types_controller_spec.rb create mode 100644 spec/factories/account_types.rb create mode 100644 spec/helpers/account_types_helper_spec.rb create mode 100644 spec/models/account_type_spec.rb create mode 100644 spec/requests/account_types_spec.rb create mode 100644 spec/routing/account_types_routing_spec.rb create mode 100644 spec/views/account_types/edit.html.haml_spec.rb create mode 100644 spec/views/account_types/index.html.haml_spec.rb create mode 100644 spec/views/account_types/new.html.haml_spec.rb create mode 100644 spec/views/account_types/show.html.haml_spec.rb diff --git a/app/assets/javascripts/account_types.js.coffee b/app/assets/javascripts/account_types.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/account_types.js.coffee @@ -0,0 +1,3 @@ +# 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_types_controller.rb b/app/controllers/account_types_controller.rb new file mode 100644 index 000000000..73011a503 --- /dev/null +++ b/app/controllers/account_types_controller.rb @@ -0,0 +1,83 @@ +class AccountTypesController < ApplicationController + # GET /account_types + # GET /account_types.json + def index + @account_types = AccountType.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @account_types } + end + end + + # GET /account_types/1 + # GET /account_types/1.json + def show + @account_type = AccountType.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @account_type } + end + end + + # GET /account_types/new + # GET /account_types/new.json + def new + @account_type = AccountType.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @account_type } + end + end + + # GET /account_types/1/edit + def edit + @account_type = AccountType.find(params[:id]) + end + + # POST /account_types + # POST /account_types.json + def create + @account_type = AccountType.new(params[:account_type]) + + respond_to do |format| + if @account_type.save + format.html { redirect_to @account_type, notice: 'Account type was successfully created.' } + format.json { render json: @account_type, status: :created, location: @account_type } + else + format.html { render action: "new" } + format.json { render json: @account_type.errors, status: :unprocessable_entity } + end + end + end + + # PUT /account_types/1 + # PUT /account_types/1.json + def update + @account_type = AccountType.find(params[:id]) + + respond_to do |format| + if @account_type.update_attributes(params[:account_type]) + format.html { redirect_to @account_type, notice: 'Account type was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @account_type.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /account_types/1 + # DELETE /account_types/1.json + def destroy + @account_type = AccountType.find(params[:id]) + @account_type.destroy + + respond_to do |format| + format.html { redirect_to account_types_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/account_types_helper.rb b/app/helpers/account_types_helper.rb new file mode 100644 index 000000000..c56061a3a --- /dev/null +++ b/app/helpers/account_types_helper.rb @@ -0,0 +1,2 @@ +module AccountTypesHelper +end diff --git a/app/models/account_detail.rb b/app/models/account_detail.rb index bce738194..2714e6d29 100644 --- a/app/models/account_detail.rb +++ b/app/models/account_detail.rb @@ -1,4 +1,5 @@ class AccountDetail < ActiveRecord::Base - attr_accessible :account_type, :member_id, :paid_until + attr_accessible :account_type_id, :member_id, :paid_until belongs_to :member + belongs_to :account_type end diff --git a/app/models/account_type.rb b/app/models/account_type.rb new file mode 100644 index 000000000..d9b0df081 --- /dev/null +++ b/app/models/account_type.rb @@ -0,0 +1,3 @@ +class AccountType < ActiveRecord::Base + attr_accessible :is_paid, :is_permanent_paid, :name +end diff --git a/app/views/account_details/show.html.haml b/app/views/account_details/show.html.haml index 55993efae..4ecb8ad74 100644 --- a/app/views/account_details/show.html.haml +++ b/app/views/account_details/show.html.haml @@ -5,7 +5,7 @@ = @account_detail.member_id %p %b Account type: - = @account_detail.account_type + = @account_detail.account_type.name %p %b Paid until: = @account_detail.paid_until diff --git a/app/views/account_types/_form.html.haml b/app/views/account_types/_form.html.haml new file mode 100644 index 000000000..12fcda225 --- /dev/null +++ b/app/views/account_types/_form.html.haml @@ -0,0 +1,19 @@ += form_for @account_type do |f| + - if @account_type.errors.any? + #error_explanation + %h2= "#{pluralize(@account_type.errors.count, "error")} prohibited this account_type from being saved:" + %ul + - @account_type.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :name + = f.text_field :name + .field + = f.label :is_paid + = f.check_box :is_paid + .field + = f.label :is_permanent_paid + = f.check_box :is_permanent_paid + .actions + = f.submit 'Save' diff --git a/app/views/account_types/edit.html.haml b/app/views/account_types/edit.html.haml new file mode 100644 index 000000000..e8d328a21 --- /dev/null +++ b/app/views/account_types/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing account_type + += render 'form' + += link_to 'Show', @account_type +\| += link_to 'Back', account_types_path diff --git a/app/views/account_types/index.html.haml b/app/views/account_types/index.html.haml new file mode 100644 index 000000000..a27434af4 --- /dev/null +++ b/app/views/account_types/index.html.haml @@ -0,0 +1,23 @@ +%h1 Listing account_types + +%table + %tr + %th Name + %th Is paid + %th Is permanent paid + %th + %th + %th + + - @account_types.each do |account_type| + %tr + %td= account_type.name + %td= account_type.is_paid + %td= account_type.is_permanent_paid + %td= link_to 'Show', account_type + %td= link_to 'Edit', edit_account_type_path(account_type) + %td= link_to 'Destroy', account_type, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Account type', new_account_type_path diff --git a/app/views/account_types/new.html.haml b/app/views/account_types/new.html.haml new file mode 100644 index 000000000..bf85a1baf --- /dev/null +++ b/app/views/account_types/new.html.haml @@ -0,0 +1,5 @@ +%h1 New account_type + += render 'form' + += link_to 'Back', account_types_path diff --git a/app/views/account_types/show.html.haml b/app/views/account_types/show.html.haml new file mode 100644 index 000000000..cb8993a27 --- /dev/null +++ b/app/views/account_types/show.html.haml @@ -0,0 +1,15 @@ +%p#notice= notice + +%p + %b Name: + = @account_type.name +%p + %b Is paid: + = @account_type.is_paid +%p + %b Is permanent paid: + = @account_type.is_permanent_paid + += link_to 'Edit', edit_account_type_path(@account_type) +\| += link_to 'Back', account_types_path diff --git a/config/routes.rb b/config/routes.rb index 463ad4041..1d6ab4adc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Growstuff::Application.routes.draw do + resources :account_types + + resources :account_details diff --git a/db/migrate/20130517015920_create_account_details.rb b/db/migrate/20130517015920_create_account_details.rb index c4fc5baef..8eb899fd5 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.integer :account_type + t.integer :account_type_id t.datetime :paid_until t.timestamps diff --git a/db/migrate/20130517051922_create_account_types.rb b/db/migrate/20130517051922_create_account_types.rb new file mode 100644 index 000000000..d300701d7 --- /dev/null +++ b/db/migrate/20130517051922_create_account_types.rb @@ -0,0 +1,11 @@ +class CreateAccountTypes < ActiveRecord::Migration + def change + create_table :account_types do |t| + t.string :name + t.boolean :is_paid + t.boolean :is_permanent_paid + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fb5dd517a..6798d6d9a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,22 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130517015920) do +ActiveRecord::Schema.define(:version => 20130517051922) do create_table "account_details", :force => true do |t| - t.integer "member_id", :null => false - t.string "account_type", :default => "free", :null => false + 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 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "account_types", :force => true do |t| + t.string "name" + t.boolean "is_paid" + t.boolean "is_permanent_paid" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "authentications", :force => true do |t| diff --git a/spec/controllers/account_types_controller_spec.rb b/spec/controllers/account_types_controller_spec.rb new file mode 100644 index 000000000..2aa8517ac --- /dev/null +++ b/spec/controllers/account_types_controller_spec.rb @@ -0,0 +1,164 @@ +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 AccountTypesController do + + # This should return the minimal set of attributes required to create a valid + # AccountType. As you add validations to AccountType, be sure to + # update the return value of this method accordingly. + def valid_attributes + { "name" => "MyString" } + 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 + # AccountTypesController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all account_types as @account_types" do + account_type = AccountType.create! valid_attributes + get :index, {}, valid_session + assigns(:account_types).should eq([account_type]) + end + end + + describe "GET show" do + it "assigns the requested account_type as @account_type" do + account_type = AccountType.create! valid_attributes + get :show, {:id => account_type.to_param}, valid_session + assigns(:account_type).should eq(account_type) + end + end + + describe "GET new" do + it "assigns a new account_type as @account_type" do + get :new, {}, valid_session + assigns(:account_type).should be_a_new(AccountType) + end + end + + describe "GET edit" do + it "assigns the requested account_type as @account_type" do + account_type = AccountType.create! valid_attributes + get :edit, {:id => account_type.to_param}, valid_session + assigns(:account_type).should eq(account_type) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new AccountType" do + expect { + post :create, {:account_type => valid_attributes}, valid_session + }.to change(AccountType, :count).by(1) + end + + it "assigns a newly created account_type as @account_type" do + post :create, {:account_type => valid_attributes}, valid_session + assigns(:account_type).should be_a(AccountType) + assigns(:account_type).should be_persisted + end + + it "redirects to the created account_type" do + post :create, {:account_type => valid_attributes}, valid_session + response.should redirect_to(AccountType.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved account_type as @account_type" do + # Trigger the behavior that occurs when invalid params are submitted + AccountType.any_instance.stub(:save).and_return(false) + post :create, {:account_type => { "name" => "invalid value" }}, valid_session + assigns(:account_type).should be_a_new(AccountType) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + AccountType.any_instance.stub(:save).and_return(false) + post :create, {:account_type => { "name" => "invalid value" }}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested account_type" do + account_type = AccountType.create! valid_attributes + # Assuming there are no other account_types in the database, this + # specifies that the AccountType created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + AccountType.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" }) + put :update, {:id => account_type.to_param, :account_type => { "name" => "MyString" }}, valid_session + end + + it "assigns the requested account_type as @account_type" do + account_type = AccountType.create! valid_attributes + put :update, {:id => account_type.to_param, :account_type => valid_attributes}, valid_session + assigns(:account_type).should eq(account_type) + end + + it "redirects to the account_type" do + account_type = AccountType.create! valid_attributes + put :update, {:id => account_type.to_param, :account_type => valid_attributes}, valid_session + response.should redirect_to(account_type) + end + end + + describe "with invalid params" do + it "assigns the account_type as @account_type" do + account_type = AccountType.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + AccountType.any_instance.stub(:save).and_return(false) + put :update, {:id => account_type.to_param, :account_type => { "name" => "invalid value" }}, valid_session + assigns(:account_type).should eq(account_type) + end + + it "re-renders the 'edit' template" do + account_type = AccountType.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + AccountType.any_instance.stub(:save).and_return(false) + put :update, {:id => account_type.to_param, :account_type => { "name" => "invalid value" }}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested account_type" do + account_type = AccountType.create! valid_attributes + expect { + delete :destroy, {:id => account_type.to_param}, valid_session + }.to change(AccountType, :count).by(-1) + end + + it "redirects to the account_types list" do + account_type = AccountType.create! valid_attributes + delete :destroy, {:id => account_type.to_param}, valid_session + response.should redirect_to(account_types_url) + end + end + +end diff --git a/spec/factories/account_details.rb b/spec/factories/account_details.rb index 40e073679..a1970165c 100644 --- a/spec/factories/account_details.rb +++ b/spec/factories/account_details.rb @@ -2,8 +2,8 @@ FactoryGirl.define do factory :account_detail do - member_id 1 - account_type 1 + member + account_type paid_until "2013-05-17 11:59:20" end end diff --git a/spec/factories/account_types.rb b/spec/factories/account_types.rb new file mode 100644 index 000000000..fa411ffbe --- /dev/null +++ b/spec/factories/account_types.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :account_type do + name "MyString" + is_paid false + is_permanent_paid false + end +end diff --git a/spec/helpers/account_types_helper_spec.rb b/spec/helpers/account_types_helper_spec.rb new file mode 100644 index 000000000..bb01d3c45 --- /dev/null +++ b/spec/helpers/account_types_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the AccountTypesHelper. For example: +# +# describe AccountTypesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe AccountTypesHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/account_type_spec.rb b/spec/models/account_type_spec.rb new file mode 100644 index 000000000..c9bf250d9 --- /dev/null +++ b/spec/models/account_type_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe AccountType do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/account_types_spec.rb b/spec/requests/account_types_spec.rb new file mode 100644 index 000000000..c7d67ac6b --- /dev/null +++ b/spec/requests/account_types_spec.rb @@ -0,0 +1,11 @@ +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 diff --git a/spec/routing/account_types_routing_spec.rb b/spec/routing/account_types_routing_spec.rb new file mode 100644 index 000000000..456cedebe --- /dev/null +++ b/spec/routing/account_types_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe AccountTypesController do + describe "routing" do + + it "routes to #index" do + get("/account_types").should route_to("account_types#index") + end + + it "routes to #new" do + get("/account_types/new").should route_to("account_types#new") + end + + it "routes to #show" do + get("/account_types/1").should route_to("account_types#show", :id => "1") + end + + it "routes to #edit" do + get("/account_types/1/edit").should route_to("account_types#edit", :id => "1") + end + + it "routes to #create" do + post("/account_types").should route_to("account_types#create") + end + + it "routes to #update" do + put("/account_types/1").should route_to("account_types#update", :id => "1") + end + + it "routes to #destroy" do + delete("/account_types/1").should route_to("account_types#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 index 7b02196fe..de8c793bd 100644 --- a/spec/views/account_details/edit.html.haml_spec.rb +++ b/spec/views/account_details/edit.html.haml_spec.rb @@ -2,10 +2,9 @@ require 'spec_helper' describe "account_details/edit" do before(:each) do - @account_detail = assign(:account_detail, stub_model(AccountDetail, - :member_id => 1, - :account_type => 1 - )) + @account_detail = assign(:account_detail, + FactoryGirl.create(:account_detail) + ) end it "renders the edit account_detail form" do diff --git a/spec/views/account_details/index.html.haml_spec.rb b/spec/views/account_details/index.html.haml_spec.rb index 619f7ddf0..a9d8314b6 100644 --- a/spec/views/account_details/index.html.haml_spec.rb +++ b/spec/views/account_details/index.html.haml_spec.rb @@ -2,22 +2,13 @@ require 'spec_helper' describe "account_details/index" do before(:each) do - assign(:account_details, [ - stub_model(AccountDetail, - :member_id => 1, - :account_type => 1 - ), - stub_model(AccountDetail, - :member_id => 1, - :account_type => 1 - ) - ]) + @account_detail = FactoryGirl.create(: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 => 1.to_s, :count => 2 - assert_select "tr>td", :text => "Account Type".to_s, :count => 2 + 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 index a4ece5750..553f5f15e 100644 --- a/spec/views/account_details/new.html.haml_spec.rb +++ b/spec/views/account_details/new.html.haml_spec.rb @@ -2,10 +2,7 @@ require 'spec_helper' describe "account_details/new" do before(:each) do - assign(:account_detail, stub_model(AccountDetail, - :member_id => 1, - :account_type => 1 - ).as_new_record) + assign(:account_detail, FactoryGirl.create(:account_detail)) end it "renders new account_detail form" do diff --git a/spec/views/account_details/show.html.haml_spec.rb b/spec/views/account_details/show.html.haml_spec.rb index 633dd6ee4..df73ec69c 100644 --- a/spec/views/account_details/show.html.haml_spec.rb +++ b/spec/views/account_details/show.html.haml_spec.rb @@ -2,16 +2,16 @@ require 'spec_helper' describe "account_details/show" do before(:each) do - @account_detail = assign(:account_detail, stub_model(AccountDetail, - :member_id => 1, - :account_type => 1 - )) + @account_detail = assign(:account_detail, + FactoryGirl.create(:account_detail) + ) end it "renders attributes in

" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - rendered.should match(/1/) - rendered.should match(/Account Type/) + rendered.should contain @account_detail.member_id.to_s + rendered.should contain @account_detail.account_type.name + rendered.should contain @account_detail.paid_until.to_s end end diff --git a/spec/views/account_types/edit.html.haml_spec.rb b/spec/views/account_types/edit.html.haml_spec.rb new file mode 100644 index 000000000..bb5fbf433 --- /dev/null +++ b/spec/views/account_types/edit.html.haml_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe "account_types/edit" do + before(:each) do + @account_type = assign(:account_type, stub_model(AccountType, + :name => "MyString", + :is_paid => false, + :is_permanent_paid => false + )) + end + + it "renders the edit account_type form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => account_types_path(@account_type), :method => "post" do + assert_select "input#account_type_name", :name => "account_type[name]" + assert_select "input#account_type_is_paid", :name => "account_type[is_paid]" + assert_select "input#account_type_is_permanent_paid", :name => "account_type[is_permanent_paid]" + end + end +end diff --git a/spec/views/account_types/index.html.haml_spec.rb b/spec/views/account_types/index.html.haml_spec.rb new file mode 100644 index 000000000..cded5ef32 --- /dev/null +++ b/spec/views/account_types/index.html.haml_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe "account_types/index" do + before(:each) do + @type = FactoryGirl.create(:account_type) + assign(:account_types, [@type, @type]) + end + + it "renders a list of account_types" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => @type.name.to_s, :count => 2 + end +end diff --git a/spec/views/account_types/new.html.haml_spec.rb b/spec/views/account_types/new.html.haml_spec.rb new file mode 100644 index 000000000..3babc2fb9 --- /dev/null +++ b/spec/views/account_types/new.html.haml_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe "account_types/new" do + before(:each) do + assign(:account_type, stub_model(AccountType, + :name => "MyString", + :is_paid => false, + :is_permanent_paid => false + ).as_new_record) + end + + it "renders new account_type form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => account_types_path, :method => "post" do + assert_select "input#account_type_name", :name => "account_type[name]" + assert_select "input#account_type_is_paid", :name => "account_type[is_paid]" + assert_select "input#account_type_is_permanent_paid", :name => "account_type[is_permanent_paid]" + end + end +end diff --git a/spec/views/account_types/show.html.haml_spec.rb b/spec/views/account_types/show.html.haml_spec.rb new file mode 100644 index 000000000..941026cf4 --- /dev/null +++ b/spec/views/account_types/show.html.haml_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe "account_types/show" do + before(:each) do + @account_type = assign(:account_type, stub_model(AccountType, + :name => "Name", + :is_paid => false, + :is_permanent_paid => false + )) + end + + it "renders attributes in

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/Name/) + rendered.should match(/false/) + rendered.should match(/false/) + end +end