From 534cbdf54712237a16189a3646e9622c18f54141 Mon Sep 17 00:00:00 2001 From: Jonathan Linowes Date: Sat, 17 Mar 2012 22:47:08 -0400 Subject: [PATCH] added person resource and migration --- app/assets/javascripts/people.js.coffee | 3 + app/controllers/people_controller.rb | 83 +++++++++++ app/helpers/people_helper.rb | 2 + app/models/person.rb | 2 + app/views/people/_form.html.haml | 20 +++ app/views/people/edit.html.haml | 7 + app/views/people/index.html.haml | 43 ++++++ app/views/people/new.html.haml | 5 + app/views/people/show.html.haml | 45 ++++++ config/application.rb | 10 +- config/initializers/simple_form.rb | 3 + config/locales/simple_form.en.yml | 5 + config/routes.rb | 2 + db/migrate/20120318022557_create_people.rb | 21 +++ db/schema.rb | 20 ++- doc/step by step.txt | 37 +++-- lib/extras/simple_form_extensions.rb | 21 +++ spec/controllers/people_controller_spec.rb | 164 +++++++++++++++++++++ spec/factories/people.rb | 19 +++ spec/helpers/people_helper_spec.rb | 15 ++ spec/models/person_spec.rb | 5 + spec/requests/people_spec.rb | 11 ++ spec/routing/people_routing_spec.rb | 35 +++++ spec/views/people/edit.html.haml_spec.rb | 38 +++++ spec/views/people/index.html.haml_spec.rb | 50 +++++++ spec/views/people/new.html.haml_spec.rb | 38 +++++ spec/views/people/show.html.haml_spec.rb | 35 +++++ 27 files changed, 717 insertions(+), 22 deletions(-) create mode 100644 app/assets/javascripts/people.js.coffee create mode 100644 app/controllers/people_controller.rb create mode 100644 app/helpers/people_helper.rb create mode 100644 app/models/person.rb create mode 100644 app/views/people/_form.html.haml create mode 100644 app/views/people/edit.html.haml create mode 100644 app/views/people/index.html.haml create mode 100644 app/views/people/new.html.haml create mode 100644 app/views/people/show.html.haml create mode 100644 db/migrate/20120318022557_create_people.rb create mode 100644 lib/extras/simple_form_extensions.rb create mode 100644 spec/controllers/people_controller_spec.rb create mode 100644 spec/factories/people.rb create mode 100644 spec/helpers/people_helper_spec.rb create mode 100644 spec/models/person_spec.rb create mode 100644 spec/requests/people_spec.rb create mode 100644 spec/routing/people_routing_spec.rb create mode 100644 spec/views/people/edit.html.haml_spec.rb create mode 100644 spec/views/people/index.html.haml_spec.rb create mode 100644 spec/views/people/new.html.haml_spec.rb create mode 100644 spec/views/people/show.html.haml_spec.rb diff --git a/app/assets/javascripts/people.js.coffee b/app/assets/javascripts/people.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/people.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/people_controller.rb b/app/controllers/people_controller.rb new file mode 100644 index 0000000..f65fb53 --- /dev/null +++ b/app/controllers/people_controller.rb @@ -0,0 +1,83 @@ +class PeopleController < ApplicationController + # GET /people + # GET /people.json + def index + @people = Person.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @people } + end + end + + # GET /people/1 + # GET /people/1.json + def show + @person = Person.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @person } + end + end + + # GET /people/new + # GET /people/new.json + def new + @person = Person.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @person } + end + end + + # GET /people/1/edit + def edit + @person = Person.find(params[:id]) + end + + # POST /people + # POST /people.json + def create + @person = Person.new(params[:person]) + + respond_to do |format| + if @person.save + format.html { redirect_to @person, notice: 'Person was successfully created.' } + format.json { render json: @person, status: :created, location: @person } + else + format.html { render action: "new" } + format.json { render json: @person.errors, status: :unprocessable_entity } + end + end + end + + # PUT /people/1 + # PUT /people/1.json + def update + @person = Person.find(params[:id]) + + respond_to do |format| + if @person.update_attributes(params[:person]) + format.html { redirect_to @person, notice: 'Person was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @person.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /people/1 + # DELETE /people/1.json + def destroy + @person = Person.find(params[:id]) + @person.destroy + + respond_to do |format| + format.html { redirect_to people_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb new file mode 100644 index 0000000..b682fbf --- /dev/null +++ b/app/helpers/people_helper.rb @@ -0,0 +1,2 @@ +module PeopleHelper +end diff --git a/app/models/person.rb b/app/models/person.rb new file mode 100644 index 0000000..2f2e286 --- /dev/null +++ b/app/models/person.rb @@ -0,0 +1,2 @@ +class Person < ActiveRecord::Base +end diff --git a/app/views/people/_form.html.haml b/app/views/people/_form.html.haml new file mode 100644 index 0000000..938eb4f --- /dev/null +++ b/app/views/people/_form.html.haml @@ -0,0 +1,20 @@ += simple_form_for(@person) do |f| + = f.error_notification + + .form-inputs + = f.input :last_name + = f.input :first_name + = f.input :middle_name + = f.input :maden + = f.input :prefix + = f.input :suffix + = f.input :gender + = f.input :birth_date + = f.input :death_date + = f.input :death_hebrew_date_day + = f.input :death_hebrew_date_month + = f.input :death_hebrew_date_year + = f.input :death_after_sunset + + .form-actions + = f.button :wrapped, :cancel => people_path diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml new file mode 100644 index 0000000..37ae9d8 --- /dev/null +++ b/app/views/people/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing person + += render 'form' + += link_to 'Show', @person +\| += link_to 'Back', people_path diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml new file mode 100644 index 0000000..3a1e728 --- /dev/null +++ b/app/views/people/index.html.haml @@ -0,0 +1,43 @@ +%h1 Listing people + +%table + %tr + %th Last name + %th First name + %th Middle name + %th Maden + %th Prefix + %th Suffix + %th Gender + %th Birth date + %th Death date + %th Death hebrew date day + %th Death hebrew date month + %th Death hebrew date year + %th Death after sunset + %th + %th + %th + + - @people.each do |person| + %tr + %td= person.last_name + %td= person.first_name + %td= person.middle_name + %td= person.maden + %td= person.prefix + %td= person.suffix + %td= person.gender + %td= person.birth_date + %td= person.death_date + %td= person.death_hebrew_date_day + %td= person.death_hebrew_date_month + %td= person.death_hebrew_date_year + %td= person.death_after_sunset + %td= link_to 'Show', person + %td= link_to 'Edit', edit_person_path(person) + %td= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete + +%br + += link_to 'New Person', new_person_path diff --git a/app/views/people/new.html.haml b/app/views/people/new.html.haml new file mode 100644 index 0000000..ae8fc42 --- /dev/null +++ b/app/views/people/new.html.haml @@ -0,0 +1,5 @@ +%h1 New person + += render 'form' + += link_to 'Back', people_path diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml new file mode 100644 index 0000000..8da6516 --- /dev/null +++ b/app/views/people/show.html.haml @@ -0,0 +1,45 @@ +%p#notice= notice + +%p + %b Last name: + = @person.last_name +%p + %b First name: + = @person.first_name +%p + %b Middle name: + = @person.middle_name +%p + %b Maden: + = @person.maden +%p + %b Prefix: + = @person.prefix +%p + %b Suffix: + = @person.suffix +%p + %b Gender: + = @person.gender +%p + %b Birth date: + = @person.birth_date +%p + %b Death date: + = @person.death_date +%p + %b Death hebrew date day: + = @person.death_hebrew_date_day +%p + %b Death hebrew date month: + = @person.death_hebrew_date_month +%p + %b Death hebrew date year: + = @person.death_hebrew_date_year +%p + %b Death after sunset: + = @person.death_after_sunset + += link_to 'Edit', edit_person_path(@person) +\| += link_to 'Back', people_path diff --git a/config/application.rb b/config/application.rb index 4e01f33..aca1491 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,6 +23,7 @@ class Application < Rails::Application # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths += %W(#{config.root}/lib/extras) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. @@ -63,13 +64,6 @@ class Application < Rails::Application config.assets.version = '1.0' config.assets.initialize_on_precompile = false - - config.generators do |g| - g.form_builder :simple_form - g.template_engine :haml - g.test_framework :rspec, :fixture => true - g.fixture_replacement :factory_girl, :dir => 'spec/factories' - end - + end end diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index ab84483..85892c8 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -1,3 +1,5 @@ +require 'simple_form_extensions' + # Use this setup block to configure all options available in SimpleForm. SimpleForm.setup do |config| # Wrappers are used by the form builder to generate a @@ -137,6 +139,7 @@ # You can define the class to use on all forms. Default is simple_form. # config.form_class = :simple_form + config.form_class = 'simple_form form-horizontal' # You can define which elements should obtain additional classes # config.generate_additional_classes_for = [:wrapper, :label, :input] diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 409e265..eb99e3f 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -21,4 +21,9 @@ en: # hints: # username: 'User name to sign in.' # password: 'No special characters, please.' + creating: "Creating..." + updating: 'Updating...' + buttons: + or: 'or' + cancel: 'cancel' diff --git a/config/routes.rb b/config/routes.rb index fa9eed1..6a658b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Ym32::Application.routes.draw do + resources :people + match 'about' => 'pages#about' root :to => 'pages#home' diff --git a/db/migrate/20120318022557_create_people.rb b/db/migrate/20120318022557_create_people.rb new file mode 100644 index 0000000..977bf8a --- /dev/null +++ b/db/migrate/20120318022557_create_people.rb @@ -0,0 +1,21 @@ +class CreatePeople < ActiveRecord::Migration + def change + create_table :people do |t| + t.string :last_name + t.string :first_name + t.string :middle_name + t.string :maden + t.string :prefix + t.string :suffix + t.string :gender + t.date :birth_date + t.date :death_date + t.integer :death_hebrew_date_day + t.integer :death_hebrew_date_month + t.integer :death_hebrew_date_year + t.boolean :death_after_sunset + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b5e6a79..12e7ee1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,24 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 0) do +ActiveRecord::Schema.define(:version => 20120318022557) do + + create_table "people", :force => true do |t| + t.string "last_name" + t.string "first_name" + t.string "middle_name" + t.string "maden" + t.string "prefix" + t.string "suffix" + t.string "gender" + t.date "birth_date" + t.date "death_date" + t.integer "death_hebrew_date_day" + t.integer "death_hebrew_date_month" + t.integer "death_hebrew_date_year" + t.boolean "death_after_sunset" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end end diff --git a/doc/step by step.txt b/doc/step by step.txt index 584dba1..b7bd85c 100644 --- a/doc/step by step.txt +++ b/doc/step by step.txt @@ -28,17 +28,12 @@ Gemfile gem 'haml-rails' gem 'simple_form' -config/application.rb - config.generators do |g| - g.form_builder :simple_form - g.template_engine :haml - end - $ bundle $ rails g simple_form:install $ rails g scaffold => Template engine: Default: haml + Fixture replacement: Default: factory_girl Form builder: Default: simple_form ## --------------- @@ -54,12 +49,6 @@ Gemfile gem "capybara" end -config/application.rb - config.generators do |g| - g.test_framework :rspec, :fixture => true - g.fixture_replacement :factory_girl, :dir => 'spec/factories' - end - $ bundle install $ rails g rspec:install FAILS @@ -215,6 +204,21 @@ simple_form (again) = simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form| +tweaks to simple_form for bootstrap + https://github.com/plataformatec/simple_form/wiki/Twitter-Bootstrap-v2-and-simple_form-v2 + config/initializers/simple_form.rb + config.form_class = 'simple_form form-horizontal' + lib/extras/simple_form_extension.rb + ...see wiki + config/application.rb + config.autoload_paths += %W(#{config.root}/lib/extras) + config/locales/simple_form.en.yml + ... + views/people/_form.html.haml + replace f.button :submit with + = f.button :wrapped, :cancel => people_path + + using sass instead of less Gemfile gem 'bootstrap-sass' @@ -231,7 +235,14 @@ re-deploy ## --------------- -## +## people + +$ rails g scaffold person last_name first_name middle_name maden prefix suffix gender birth_date:date death_date:date death_hebrew_date_day:integer death_hebrew_date_month:integer death_hebrew_date_year:integer death_after_sunset:boolean --skip-stylesheets + +$ rake db:migrate +$ rails s + + ## --------------- ## ## --------------- diff --git a/lib/extras/simple_form_extensions.rb b/lib/extras/simple_form_extensions.rb new file mode 100644 index 0000000..8c2e50f --- /dev/null +++ b/lib/extras/simple_form_extensions.rb @@ -0,0 +1,21 @@ +# ref: https://github.com/plataformatec/simple_form/wiki/Twitter-Bootstrap-v2-and-simple_form-v2 +# will allow you to do +# = f.button :wrapped, :cancel => posts_path + +module WrappedButton + def wrapped_button(*args, &block) + template.content_tag :div, :class => "form-actions" do + options = args.extract_options! + loading = self.object.new_record? ? I18n.t('simple_form.creating') : I18n.t('simple_form.updating') + options[:"data-loading-text"] = [loading, options[:"data-loading-text"]].compact + options[:class] = ['btn-primary', options[:class]].compact + args << options + if cancel = options.delete(:cancel) + submit(*args, &block) + ' ' + I18n.t('simple_form.buttons.or') + ' ' + template.link_to(I18n.t('simple_form.buttons.cancel'), cancel) + else + submit(*args, &block) + end + end + end +end +SimpleForm::FormBuilder.send :include, WrappedButton diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb new file mode 100644 index 0000000..ceb841a --- /dev/null +++ b/spec/controllers/people_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 PeopleController do + + # This should return the minimal set of attributes required to create a valid + # Person. As you add validations to Person, be sure to + # update the return value of this method accordingly. + def valid_attributes + {} + 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 + # PeopleController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all people as @people" do + person = Person.create! valid_attributes + get :index, {}, valid_session + assigns(:people).should eq([person]) + end + end + + describe "GET show" do + it "assigns the requested person as @person" do + person = Person.create! valid_attributes + get :show, {:id => person.to_param}, valid_session + assigns(:person).should eq(person) + end + end + + describe "GET new" do + it "assigns a new person as @person" do + get :new, {}, valid_session + assigns(:person).should be_a_new(Person) + end + end + + describe "GET edit" do + it "assigns the requested person as @person" do + person = Person.create! valid_attributes + get :edit, {:id => person.to_param}, valid_session + assigns(:person).should eq(person) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Person" do + expect { + post :create, {:person => valid_attributes}, valid_session + }.to change(Person, :count).by(1) + end + + it "assigns a newly created person as @person" do + post :create, {:person => valid_attributes}, valid_session + assigns(:person).should be_a(Person) + assigns(:person).should be_persisted + end + + it "redirects to the created person" do + post :create, {:person => valid_attributes}, valid_session + response.should redirect_to(Person.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved person as @person" do + # Trigger the behavior that occurs when invalid params are submitted + Person.any_instance.stub(:save).and_return(false) + post :create, {:person => {}}, valid_session + assigns(:person).should be_a_new(Person) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Person.any_instance.stub(:save).and_return(false) + post :create, {:person => {}}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested person" do + person = Person.create! valid_attributes + # Assuming there are no other people in the database, this + # specifies that the Person created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Person.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, {:id => person.to_param, :person => {'these' => 'params'}}, valid_session + end + + it "assigns the requested person as @person" do + person = Person.create! valid_attributes + put :update, {:id => person.to_param, :person => valid_attributes}, valid_session + assigns(:person).should eq(person) + end + + it "redirects to the person" do + person = Person.create! valid_attributes + put :update, {:id => person.to_param, :person => valid_attributes}, valid_session + response.should redirect_to(person) + end + end + + describe "with invalid params" do + it "assigns the person as @person" do + person = Person.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Person.any_instance.stub(:save).and_return(false) + put :update, {:id => person.to_param, :person => {}}, valid_session + assigns(:person).should eq(person) + end + + it "re-renders the 'edit' template" do + person = Person.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Person.any_instance.stub(:save).and_return(false) + put :update, {:id => person.to_param, :person => {}}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested person" do + person = Person.create! valid_attributes + expect { + delete :destroy, {:id => person.to_param}, valid_session + }.to change(Person, :count).by(-1) + end + + it "redirects to the people list" do + person = Person.create! valid_attributes + delete :destroy, {:id => person.to_param}, valid_session + response.should redirect_to(people_url) + end + end + +end diff --git a/spec/factories/people.rb b/spec/factories/people.rb new file mode 100644 index 0000000..49fddfb --- /dev/null +++ b/spec/factories/people.rb @@ -0,0 +1,19 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :person do + last_name "MyString" + first_name "MyString" + middle_name "MyString" + maden "MyString" + prefix "MyString" + suffix "MyString" + gender "MyString" + birth_date "2012-03-17" + death_date "2012-03-17" + death_hebrew_date_day 1 + death_hebrew_date_month 1 + death_hebrew_date_year 1 + death_after_sunset false + end +end diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb new file mode 100644 index 0000000..9d4bf57 --- /dev/null +++ b/spec/helpers/people_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the PeopleHelper. For example: +# +# describe PeopleHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe PeopleHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb new file mode 100644 index 0000000..6f582eb --- /dev/null +++ b/spec/models/person_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Person do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/people_spec.rb b/spec/requests/people_spec.rb new file mode 100644 index 0000000..ba7a96c --- /dev/null +++ b/spec/requests/people_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "People" do + describe "GET /people" 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 people_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/people_routing_spec.rb b/spec/routing/people_routing_spec.rb new file mode 100644 index 0000000..70db5e0 --- /dev/null +++ b/spec/routing/people_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe PeopleController do + describe "routing" do + + it "routes to #index" do + get("/people").should route_to("people#index") + end + + it "routes to #new" do + get("/people/new").should route_to("people#new") + end + + it "routes to #show" do + get("/people/1").should route_to("people#show", :id => "1") + end + + it "routes to #edit" do + get("/people/1/edit").should route_to("people#edit", :id => "1") + end + + it "routes to #create" do + post("/people").should route_to("people#create") + end + + it "routes to #update" do + put("/people/1").should route_to("people#update", :id => "1") + end + + it "routes to #destroy" do + delete("/people/1").should route_to("people#destroy", :id => "1") + end + + end +end diff --git a/spec/views/people/edit.html.haml_spec.rb b/spec/views/people/edit.html.haml_spec.rb new file mode 100644 index 0000000..f0c26c7 --- /dev/null +++ b/spec/views/people/edit.html.haml_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe "people/edit" do + before(:each) do + @person = assign(:person, stub_model(Person, + :last_name => "MyString", + :first_name => "MyString", + :middle_name => "MyString", + :maden => "MyString", + :prefix => "MyString", + :suffix => "MyString", + :gender => "MyString", + :death_hebrew_date_day => 1, + :death_hebrew_date_month => 1, + :death_hebrew_date_year => 1, + :death_after_sunset => false + )) + end + + it "renders the edit person form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => people_path(@person), :method => "post" do + assert_select "input#person_last_name", :name => "person[last_name]" + assert_select "input#person_first_name", :name => "person[first_name]" + assert_select "input#person_middle_name", :name => "person[middle_name]" + assert_select "input#person_maden", :name => "person[maden]" + assert_select "input#person_prefix", :name => "person[prefix]" + assert_select "input#person_suffix", :name => "person[suffix]" + assert_select "input#person_gender", :name => "person[gender]" + assert_select "input#person_death_hebrew_date_day", :name => "person[death_hebrew_date_day]" + assert_select "input#person_death_hebrew_date_month", :name => "person[death_hebrew_date_month]" + assert_select "input#person_death_hebrew_date_year", :name => "person[death_hebrew_date_year]" + assert_select "input#person_death_after_sunset", :name => "person[death_after_sunset]" + end + end +end diff --git a/spec/views/people/index.html.haml_spec.rb b/spec/views/people/index.html.haml_spec.rb new file mode 100644 index 0000000..1d20205 --- /dev/null +++ b/spec/views/people/index.html.haml_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe "people/index" do + before(:each) do + assign(:people, [ + stub_model(Person, + :last_name => "Last Name", + :first_name => "First Name", + :middle_name => "Middle Name", + :maden => "Maden", + :prefix => "Prefix", + :suffix => "Suffix", + :gender => "Gender", + :death_hebrew_date_day => 1, + :death_hebrew_date_month => 2, + :death_hebrew_date_year => 3, + :death_after_sunset => false + ), + stub_model(Person, + :last_name => "Last Name", + :first_name => "First Name", + :middle_name => "Middle Name", + :maden => "Maden", + :prefix => "Prefix", + :suffix => "Suffix", + :gender => "Gender", + :death_hebrew_date_day => 1, + :death_hebrew_date_month => 2, + :death_hebrew_date_year => 3, + :death_after_sunset => false + ) + ]) + end + + it "renders a list of people" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => "Last Name".to_s, :count => 2 + assert_select "tr>td", :text => "First Name".to_s, :count => 2 + assert_select "tr>td", :text => "Middle Name".to_s, :count => 2 + assert_select "tr>td", :text => "Maden".to_s, :count => 2 + assert_select "tr>td", :text => "Prefix".to_s, :count => 2 + assert_select "tr>td", :text => "Suffix".to_s, :count => 2 + assert_select "tr>td", :text => "Gender".to_s, :count => 2 + assert_select "tr>td", :text => 1.to_s, :count => 2 + assert_select "tr>td", :text => 2.to_s, :count => 2 + assert_select "tr>td", :text => 3.to_s, :count => 2 + assert_select "tr>td", :text => false.to_s, :count => 2 + end +end diff --git a/spec/views/people/new.html.haml_spec.rb b/spec/views/people/new.html.haml_spec.rb new file mode 100644 index 0000000..92fee41 --- /dev/null +++ b/spec/views/people/new.html.haml_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe "people/new" do + before(:each) do + assign(:person, stub_model(Person, + :last_name => "MyString", + :first_name => "MyString", + :middle_name => "MyString", + :maden => "MyString", + :prefix => "MyString", + :suffix => "MyString", + :gender => "MyString", + :death_hebrew_date_day => 1, + :death_hebrew_date_month => 1, + :death_hebrew_date_year => 1, + :death_after_sunset => false + ).as_new_record) + end + + it "renders new person form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => people_path, :method => "post" do + assert_select "input#person_last_name", :name => "person[last_name]" + assert_select "input#person_first_name", :name => "person[first_name]" + assert_select "input#person_middle_name", :name => "person[middle_name]" + assert_select "input#person_maden", :name => "person[maden]" + assert_select "input#person_prefix", :name => "person[prefix]" + assert_select "input#person_suffix", :name => "person[suffix]" + assert_select "input#person_gender", :name => "person[gender]" + assert_select "input#person_death_hebrew_date_day", :name => "person[death_hebrew_date_day]" + assert_select "input#person_death_hebrew_date_month", :name => "person[death_hebrew_date_month]" + assert_select "input#person_death_hebrew_date_year", :name => "person[death_hebrew_date_year]" + assert_select "input#person_death_after_sunset", :name => "person[death_after_sunset]" + end + end +end diff --git a/spec/views/people/show.html.haml_spec.rb b/spec/views/people/show.html.haml_spec.rb new file mode 100644 index 0000000..3fd6434 --- /dev/null +++ b/spec/views/people/show.html.haml_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe "people/show" do + before(:each) do + @person = assign(:person, stub_model(Person, + :last_name => "Last Name", + :first_name => "First Name", + :middle_name => "Middle Name", + :maden => "Maden", + :prefix => "Prefix", + :suffix => "Suffix", + :gender => "Gender", + :death_hebrew_date_day => 1, + :death_hebrew_date_month => 2, + :death_hebrew_date_year => 3, + :death_after_sunset => 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(/Last Name/) + rendered.should match(/First Name/) + rendered.should match(/Middle Name/) + rendered.should match(/Maden/) + rendered.should match(/Prefix/) + rendered.should match(/Suffix/) + rendered.should match(/Gender/) + rendered.should match(/1/) + rendered.should match(/2/) + rendered.should match(/3/) + rendered.should match(/false/) + end +end