Skip to content
Browse files

added bookables

  • Loading branch information...
1 parent a8c6a3d commit 6e2230352a18bec9deb860611ad6e7d99a4359f3 Neil Edwards committed Oct 9, 2010
View
1 Gemfile
@@ -10,6 +10,7 @@ gem 'haml'
gem 'formtastic'
gem 'authlogic', :git => "http://github.com/binarylogic/authlogic.git"
gem 'flutie', :git => "http://github.com/thoughtbot/flutie.git"
+gem 'cells'
group :test, :development do
#gem "rspec-rails", ">= 2.0.0.beta.22"
View
12 Gemfile.lock
@@ -1,12 +1,12 @@
GIT
remote: git://github.com/rspec/rspec-core.git
- revision: fc37841447460a0be4d45d82e26167448e17795f
+ revision: 33a8847c2904034cfcaaf0c69ca2740d9ce5179b
specs:
rspec-core (2.0.0.rc)
GIT
remote: git://github.com/rspec/rspec-expectations.git
- revision: b1a6c848265c9912a1bb49afbae0e6cb1e50f3fd
+ revision: 6967fd6393a4c9a3aafc25045f64a54d17545834
specs:
rspec-expectations (2.0.0.rc)
diff-lcs (>= 1.1.2)
@@ -21,7 +21,7 @@ GIT
GIT
remote: git://github.com/rspec/rspec-rails.git
- revision: b45d0936d77f3e532a08fc1b49f072be05873f94
+ revision: bfb7792a7871c6cf1d6714795091f6c00475e539
specs:
rspec-rails (2.0.0.rc)
rspec (= 2.0.0.rc)
@@ -44,7 +44,7 @@ GIT
GIT
remote: http://github.com/thoughtbot/flutie.git
- revision: c43453449741e4408847b6b4a20fe683889cce91
+ revision: 7358f9f381d236cfc7ef76e4ab9da342963c229b
specs:
flutie (1.0.4)
@@ -89,6 +89,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (>= 0.0.3)
+ cells (3.4.1)
configuration (1.1.0)
cucumber (0.9.2)
builder (~> 2.1.2)
@@ -123,7 +124,7 @@ GEM
launchy (0.3.7)
configuration (>= 0.0.5)
rake (>= 0.8.1)
- mail (2.2.6.1)
+ mail (2.2.7)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
@@ -171,6 +172,7 @@ DEPENDENCIES
ZenTest
authlogic!
capybara
+ cells
cucumber
cucumber-rails
database_cleaner
View
68 app/controllers/bookables_controller.rb
@@ -0,0 +1,68 @@
+class BookablesController < ApplicationController
+ def index
+ @bookables = Bookable.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ end
+ end
+
+ def show
+ @bookable = Bookable.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ end
+ end
+
+ def new
+ @business = Business.find(params[:business_id])
+ @bookable = @business.bookables.build
+
+ respond_to do |format|
+ format.html # new.html.erb
+ end
+ end
+
+ def edit
+ @bookable = Bookable.find(params[:id])
+ end
+
+ def create
+ @business = Business.find(params[:business_id])
+ @bookable = Bookable.new(params[:bookable])
+
+ respond_to do |format|
+ if @bookable.save
+ format.html {
+ redirect_to(@bookable.business, :notice => 'Bookable was successfully created.')
+ }
+ else
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+ def update
+ @bookable = Bookable.find(params[:id])
+
+ respond_to do |format|
+ if @bookable.update_attributes(params[:bookable])
+ format.html {
+ redirect_to(@bookable, :notice => 'Bookable was successfully updated.')
+ }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ def destroy
+ @bookable = Bookable.find(params[:id])
+ @bookable.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(bookables_url) }
+ end
+ end
+end
View
2 app/helpers/bookables_helper.rb
@@ -0,0 +1,2 @@
+module BookablesHelper
+end
View
5 app/models/bookable.rb
@@ -0,0 +1,5 @@
+class Bookable < ActiveRecord::Base
+ validates_presence_of :name
+ validates_presence_of :business_id
+ belongs_to :business
+end
View
1 app/models/business.rb
@@ -1,2 +1,3 @@
class Business < ActiveRecord::Base
+ has_many :bookables
end
View
9 app/views/bookables/_bookable.html.haml
@@ -0,0 +1,9 @@
+%tr
+ %td= bookable.name
+ %td
+ = link_to 'Show', business_bookable_path(bookable.business, bookable)
+ %td
+ = link_to 'Edit', edit_business_bookable_path(bookable.business, bookable)
+ %td
+ = link_to 'Destroy', business_bookable_path(bookable.business, bookable), :confirm => 'Are you sure?', :method => :delete
+
View
7 app/views/bookables/_form.html.haml
@@ -0,0 +1,7 @@
+= semantic_form_for [@business, @bookable] do |f|
+ = f.semantic_errors :state
+ = f.inputs do
+ = f.input :name
+ = f.input :description
+ = f.input :business_id, :as => :hidden
+ = f.buttons
View
6 app/views/bookables/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing bookable</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @bookable %> |
+<%= link_to 'Back', bookables_path %>
View
12 app/views/bookables/index.html.haml
@@ -0,0 +1,12 @@
+%h1
+ Listing bookables
+%table
+ %tr
+ %th
+ Name
+ %th
+ %th
+ %th
+= render @bookables
+
+= link_to 'New Bookable', new_bookable_path
View
5 app/views/bookables/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New bookable</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', business_bookables_path(@business) %>
View
6 app/views/bookables/show.html.haml
@@ -0,0 +1,6 @@
+%h1= @bookable.name
+#description= @bookable.description
+
+= link_to 'Edit', edit_business_bookable_path(@bookable.business, @bookable)
+|
+= link_to 'Back', business_path(@bookable.business)
View
17 app/views/businesses/show.html.haml
@@ -1 +1,18 @@
%h1= @business.name
+
+%h2
+ Listing bookables
+%table
+ %tr
+ %th
+ Name
+ %th
+ Show
+ %th
+ Edit
+ %th
+ Destroy
+ =render @business.bookables
+
+
+= link_to "Add something that can be booked", new_business_bookable_path(@business)
View
2 app/views/layouts/application.html.haml
@@ -28,8 +28,8 @@
%body
#container
%header
- = render :partial=> 'shared/flashes'
= render :partial => 'shared/header'
+ = render :partial=> 'shared/flashes'
#main.yui3-g
= yield
%footer.yui3-u-1
View
4 config/routes.rb
@@ -4,7 +4,9 @@
match '/signout' => 'user_sessions#destroy', :as => :signout
resources :users
- resources :businesses
+ resources :businesses do
+ resources :bookables
+ end
resources :user_sessions
#match 'signin' => 'user_sessions#new', :as => :signin
View
15 db/migrate/20101007145228_create_bookables.rb
@@ -0,0 +1,15 @@
+class CreateBookables < ActiveRecord::Migration
+ def self.up
+ create_table :bookables do |t|
+ t.string :name
+ t.text :description
+ t.integer :business_id
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :bookables
+ end
+end
View
10 db/schema.rb
@@ -10,7 +10,15 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100929212142) do
+ActiveRecord::Schema.define(:version => 20101007145228) do
+
+ create_table "bookables", :force => true do |t|
+ t.string "name"
+ t.text "description"
+ t.integer "business_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "businesses", :force => true do |t|
t.string "name"
View
8 features/bookables.feature
@@ -4,11 +4,11 @@ Feature: Bookable items
I want to be able to define the things that can be booked
Scenario: Create a new bookable item
- Given I am I logged in
+ Given I am logged in
When I follow "Add something that can be booked"
And I fill in "Name" with "Sally"
And I fill in "Description" with "The best hairdresser in the world"
- And I press "Add"
- Then I should be on my business page
- And there should be one bookable item
+ And I press "Create Bookable"
+ Then I should be on my business page
+ And there should be 1 bookable item
And I should see "Sally"
View
6 features/step_definitions/authentication_steps.rb
@@ -28,3 +28,9 @@
UserSession.find.should be_nil
end
+Given /^I am logged in$/ do
+ Given "I have a user with the email \"neil@plasticwater.com\" and the business \"Acme\""
+ Given "I am logged in as the user \"neil@plasticwater.com\""
+end
+
+
View
3 features/step_definitions/bookable_steps.rb
@@ -0,0 +1,3 @@
+Then /^there should be (\d+) bookable item[s]?$/ do |number|
+ assert Bookable.all.count == 1
+end
View
3 features/support/paths.rb
@@ -19,6 +19,9 @@ def path_to(page_name)
when /the business page for "(.*)"/
business_path(Business.find_by_name($1))
+
+ when /my business page/
+ business_path(Business.first)
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
View
124 spec/controllers/bookables_controller_spec.rb
@@ -0,0 +1,124 @@
+require 'spec_helper'
+
+describe BookablesController do
+
+ describe "GET index" do
+ it "assigns all bookables as @bookables" do
+ #stub(Bookable).all { [mock_bookable] }
+ #get :index
+ #assigns(:bookables).should eq([mock_bookable])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested bookable as @bookable" do
+ #stub(Bookable).find("37") { mock_bookable }
+ #get :show, :id => "37"
+ #assigns(:bookable).should be(mock_bookable)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new bookable as @bookable" do
+ #stub(Bookable).new { mock_bookable }
+ #get :new
+ #assigns(:bookable).should be(mock_bookable)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested bookable as @bookable" do
+ #stub(Bookable).find("37") { mock_bookable }
+ #get :edit, :id => "37"
+ #assigns(:bookable).should be(mock_bookable)
+ end
+ end
+
+ describe "POST create" do
+
+ describe "with valid params" do
+ it "assigns a newly created bookable as @bookable" do
+ mock(my_mock = Factory(:bookable)).save {true}
+ stub(Bookable).new {my_mock}
+ post :create, :business_id => my_mock.business_id
+ assigns(:bookable).should be(my_mock)
+ end
+
+ it "redirects to the business page" do
+ mock(my_mock = Factory.build(:bookable)).save {true}
+ stub(Bookable).new({}) { my_mock }
+ post :create, :bookable => {}, :business_id => my_mock.business_id
+
+ response.should redirect_to(:controller => "businesses", :action => "show", :id => my_mock.business)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved bookable as @bookable" do
+ #stub(Bookable).new({'these' => 'params'}) { mock_bookable(:save => false) }
+ #post :create, :bookable => {'these' => 'params'}
+ #assigns(:bookable).should be(mock_bookable)
+ end
+
+ it "re-renders the 'new' template" do
+ #stub(Bookable).new { mock_bookable(:save => false) }
+ #post :create, :bookable => {}
+ #response.should render_template("new")
+ end
+ end
+
+ end
+
+ describe "PUT update" do
+
+ describe "with valid params" do
+ it "updates the requested bookable" do
+ #Bookable.should_receive(:find).with("37") { mock_bookable }
+ #mock_bookable.should_receive(:update_attributes).with({'these' => 'params'})
+ #put :update, :id => "37", :bookable => {'these' => 'params'}
+ end
+
+ it "assigns the requested bookable as @bookable" do
+ #stub(Bookable).find { mock_bookable(:update_attributes => true) }
+ #put :update, :id => "1"
+ #assigns(:bookable).should be(mock_bookable)
+ end
+
+ it "redirects to the bookable" do
+ #stub(Bookable).find { mock_bookable(:update_attributes => true) }
+ #put :update, :id => "1"
+ #response.should redirect_to(bookable_url(mock_bookable))
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the bookable as @bookable" do
+ #stub(Bookable).find { mock_bookable(:update_attributes => false) }
+ #put :update, :id => "1"
+ #assigns(:bookable).should be(mock_bookable)
+ end
+
+ it "re-renders the 'edit' template" do
+ #stub(Bookable).find { mock_bookable(:update_attributes => false) }
+ #put :update, :id => "1"
+ #response.should render_template("edit")
+ end
+ end
+
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested bookable" do
+ #Bookable.should_receive(:find).with("37") { mock_bookable }
+ #mock_bookable.should_receive(:destroy)
+ #delete :destroy, :id => "37"
+ end
+
+ it "redirects to the bookables list" do
+ #stub(Bookable).find { mock_bookable }
+ #delete :destroy, :id => "1"
+ #response.should redirect_to(bookables_url)
+ end
+ end
+
+end
View
6 spec/factories.rb
@@ -7,3 +7,9 @@
Factory.define :business do |b|
b.name "Acme Corp"
end
+
+Factory.define(:bookable) do |b|
+ b.name "My Bookable Thing"
+ b.description "This bookable thing is bookable"
+ b.business {|b| b.association(:business)}
+end
View
5 spec/models/bookable_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Bookable do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 6e22303

Please sign in to comment.
Something went wrong with that request. Please try again.