Skip to content

Commit

Permalink
added extra attributes to the tour_date model
Browse files Browse the repository at this point in the history
  • Loading branch information
levicole committed Sep 21, 2009
1 parent 220cda8 commit da7b7cc
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/models/tour_date.rb
Expand Up @@ -3,7 +3,8 @@ class TourDate < ActiveRecord::Base
validates_presence_of :city
validates_presence_of :state
validates_presence_of :date

validates_presence_of :venue

def city_state_country
"#{city}, #{state} (#{country})"
end
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/tour_dates/_form_fields.html.haml
@@ -1,6 +1,9 @@
%p
%label{:for => "date"} Show Date:
= f.date_select :date
%p
%label{:for => "venue"} Venue:
= f.text_field :venue, :class => "text"
%p
%label{:for => "City"} City:
= f.text_field :city, :class => "text"
Expand All @@ -10,3 +13,6 @@
%p
%label{:for => "country"} Country
= f.text_field :country, :class => "text"
%p
%label{:for => "description"} Description:
= f.text_area :description, :class => "text"
7 changes: 6 additions & 1 deletion app/views/admin/tour_dates/index.html.haml
@@ -1,16 +1,21 @@
%h1 Tour Dates
- unless @tour_dates.blank?
%table.index
%thead
%tr
%th Date
%th City, State (Country)
%th Venue
%th Description
%th Modify
%tbody
- @tour_dates.each do |tour_date|
%tr
%td= tour_date.date
%td= tour_date.city_state_country
%td= link_to image('remove', :alt => 'Remove link'), remove_admin_tour_date_url(:id => tour_date.id)
%td= tour_date.venue
%td= tour_date.description
%td= link_to image('remove', :alt => 'Remove link'), [:admin, tour_date], :method => :delete, :confirm => "Are you sure you want to do that?"
= link_to "Add new Tour Date", :action => "new"
- else
== Looks like you need to add some tour dates! Click #{link_to "here", :action => "new"}
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20090914004607_add_more_options_for_tour_date.rb
@@ -0,0 +1,15 @@
class AddMoreOptionsForTourDate < ActiveRecord::Migration
def self.up
add_column :tour_dates, :approved, :boolean, :default => true
add_column :tour_dates, :venue, :string
add_column :tour_dates, :description, :text
add_column :tour_dates, :tickets_link, :string
end

def self.down
remove_column :tour_dates, :approved
remove_column :tour_dates, :venue
remove_column :tour_dates, :description
remove_column :tour_dates, :tickets_link
end
end
10 changes: 10 additions & 0 deletions lib/tour_extension_tags.rb
Expand Up @@ -39,4 +39,14 @@ module TourExtensionTags
"#{tour_date.country}"
end

tag 'tour_dates:each:description' do |tag|
tour_date = tag.locals.tour_date
"#{tour_date.description}"
end

tag 'tour_dates:each:tickets_link' do |tag|
tour_date = tag.locals.tour_date
"#{tour_date.tickets_link}"
end

end
5 changes: 2 additions & 3 deletions spec/controllers/admin/tour_dates_controller_spec.rb
Expand Up @@ -2,9 +2,8 @@

describe Admin::TourDatesController do

#Delete this example and add some real ones
it "should use Admin::TourDatesController" do
controller.should be_an_instance_of(Admin::TourDatesController)
describe "POST /admin/tour_dates" do

end

end
10 changes: 10 additions & 0 deletions spec/factories.rb
@@ -0,0 +1,10 @@
Factory.define :tour_date do |f|
f.city 'Nashville'
f.state 'TN'
f.country 'US'
f.date Date.today
f.venue 'Somet Center'
f.approved true
f.description "this is a description of the event."
f.tickets_link "http://www.ticketmaster.com"
end
54 changes: 54 additions & 0 deletions spec/lib/tour_extension_tags_spec.rb
@@ -0,0 +1,54 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe "TourExtensionTags" do
dataset :pages

describe "<r:tour_dates:each>" do

before(:each) do
@tour_dates = [Factory(:tour_date)]
end

def do_nested_tag(tag)
"<r:tour_dates:each>#{tag}</r:tour_dates:each>"
end

it 'should render city_state_zip when <r:city_state_country> is nested' do
tag = do_nested_tag("<r:city_state_country />")
expected = %{Nashville, TN (US)}
pages(:home).should render(tag).as(expected)
end

it "should render city when <r:city> is nested" do
tag = do_nested_tag("<r:city />")
expected = %{Nashville}
pages(:home).should render(tag).as(expected)
end

it "should render state when <r:state> is nested" do
tag = do_nested_tag("<r:state />")
expected = "TN"
pages(:home).should render(tag).as(expected)
end

it "should render country when <r:country> is nested" do
tag = do_nested_tag("<r:country />")
expected = "US"
pages(:home).should render(tag).as(expected)
end

it "should render description when <r:description> is nested" do
tag = do_nested_tag("<r:description />")
expected = "this is a description of the event."
pages(:home).should render(tag).as(expected)
end

it "should render tickets link when <r:tickets_link> is nested" do
tag = do_nested_tag("<r:tickets_link />")
expected = "http://www.ticketmaster.com"
pages(:home).should render(tag).as(expected)
end

end

end
13 changes: 3 additions & 10 deletions spec/models/tour_date_spec.rb
Expand Up @@ -2,26 +2,19 @@

describe TourDate do

def required_attributes
{
:city => "Nashville",
:state => "TN",
:date => Date.today
}
end

it "should automatically set country to US" do
@tour_date = TourDate.new
@tour_date.country.should == "US"
end

describe "validations" do
it_should_validate_presence_of(:city, :state, :date)
it_should_validate_presence_of(:city, :state, :date, :venue)
end

describe "#city_state_country" do
it "returns the city state and country in the following format 'City, State (Country)'" do
@tour_date = TourDate.new(required_attributes)
@tour_date = Factory(:tour_date)
@tour_date.save
@tour_date.city_state_country.should == "Nashville, TN (US)"
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -17,6 +17,8 @@
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
end

require File.dirname(__FILE__) + "/factories.rb"

Spec::Runner.configure do |config|
# config.use_transactional_fixtures = true
# config.use_instantiated_fixtures = false
Expand Down Expand Up @@ -49,7 +51,7 @@ def without(*args)
def it_should_validate_presence_of(*attrs)
for attribute in attrs
it "requires the attribute: #{attribute.to_s}" do
@tour_date = TourDate.new(required_attributes.without(attribute))
@tour_date = Factory.build(:tour_date, {attribute => ''})
@tour_date.should have(1).errors_on(attribute)
end
end
Expand Down

0 comments on commit da7b7cc

Please sign in to comment.