From da7b7cc20907171614ac35b17b1e7799cf04910c Mon Sep 17 00:00:00 2001 From: LeviCole Date: Mon, 21 Sep 2009 13:09:47 -0500 Subject: [PATCH] added extra attributes to the tour_date model --- app/models/tour_date.rb | 3 +- .../admin/tour_dates/_form_fields.html.haml | 6 +++ app/views/admin/tour_dates/index.html.haml | 7 ++- ...14004607_add_more_options_for_tour_date.rb | 15 ++++++ lib/tour_extension_tags.rb | 10 ++++ .../admin/tour_dates_controller_spec.rb | 5 +- spec/factories.rb | 10 ++++ spec/lib/tour_extension_tags_spec.rb | 54 +++++++++++++++++++ spec/models/tour_date_spec.rb | 13 ++--- spec/spec_helper.rb | 4 +- 10 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20090914004607_add_more_options_for_tour_date.rb create mode 100644 spec/factories.rb create mode 100644 spec/lib/tour_extension_tags_spec.rb diff --git a/app/models/tour_date.rb b/app/models/tour_date.rb index 53a0ddd..338584b 100644 --- a/app/models/tour_date.rb +++ b/app/models/tour_date.rb @@ -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 diff --git a/app/views/admin/tour_dates/_form_fields.html.haml b/app/views/admin/tour_dates/_form_fields.html.haml index 66fb97d..02f33f4 100644 --- a/app/views/admin/tour_dates/_form_fields.html.haml +++ b/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" @@ -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" diff --git a/app/views/admin/tour_dates/index.html.haml b/app/views/admin/tour_dates/index.html.haml index 4a1d25a..a6ead63 100644 --- a/app/views/admin/tour_dates/index.html.haml +++ b/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"} diff --git a/db/migrate/20090914004607_add_more_options_for_tour_date.rb b/db/migrate/20090914004607_add_more_options_for_tour_date.rb new file mode 100644 index 0000000..efae000 --- /dev/null +++ b/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 diff --git a/lib/tour_extension_tags.rb b/lib/tour_extension_tags.rb index 4803d68..fa13e10 100644 --- a/lib/tour_extension_tags.rb +++ b/lib/tour_extension_tags.rb @@ -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 \ No newline at end of file diff --git a/spec/controllers/admin/tour_dates_controller_spec.rb b/spec/controllers/admin/tour_dates_controller_spec.rb index 5791dbd..b24bd55 100644 --- a/spec/controllers/admin/tour_dates_controller_spec.rb +++ b/spec/controllers/admin/tour_dates_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 0000000..9d8a064 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/lib/tour_extension_tags_spec.rb b/spec/lib/tour_extension_tags_spec.rb new file mode 100644 index 0000000..0631685 --- /dev/null +++ b/spec/lib/tour_extension_tags_spec.rb @@ -0,0 +1,54 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe "TourExtensionTags" do + dataset :pages + + describe "" do + + before(:each) do + @tour_dates = [Factory(:tour_date)] + end + + def do_nested_tag(tag) + "#{tag}" + end + + it 'should render city_state_zip when is nested' do + tag = do_nested_tag("") + expected = %{Nashville, TN (US)} + pages(:home).should render(tag).as(expected) + end + + it "should render city when is nested" do + tag = do_nested_tag("") + expected = %{Nashville} + pages(:home).should render(tag).as(expected) + end + + it "should render state when is nested" do + tag = do_nested_tag("") + expected = "TN" + pages(:home).should render(tag).as(expected) + end + + it "should render country when is nested" do + tag = do_nested_tag("") + expected = "US" + pages(:home).should render(tag).as(expected) + end + + it "should render description when is nested" do + tag = do_nested_tag("") + expected = "this is a description of the event." + pages(:home).should render(tag).as(expected) + end + + it "should render tickets link when is nested" do + tag = do_nested_tag("") + expected = "http://www.ticketmaster.com" + pages(:home).should render(tag).as(expected) + end + + end + +end diff --git a/spec/models/tour_date_spec.rb b/spec/models/tour_date_spec.rb index f2eb56e..b925978 100644 --- a/spec/models/tour_date_spec.rb +++ b/spec/models/tour_date_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac2e599..c060e3e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 @@ -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