Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

created decorator specs and moved some specs for decorators out of mo…

…dels
  • Loading branch information...
commit 7ad2df86bedf9b97075b0fd5d36d01f5e524051e 1 parent e5a47d0
@danielspaniel danielspaniel authored
View
5 Gemfile
@@ -31,12 +31,11 @@ gem 'whenever', :require => false
# these two strongly resist being in asset group
gem 'handlebars_assets'
gem 'haml_assets'
-#group :assets do
+group :assets do
gem 'coffee-rails'
- gem 'sprockets'
gem 'sass-rails'
gem 'uglifier'
-#end
+end
group :development, :test do
gem 'wirble'
View
1  Gemfile.lock
@@ -305,7 +305,6 @@ DEPENDENCIES
sass-rails
schedule_atts
spork
- sprockets
therubyracer
timecop
turn
View
27 spec/decorators/business_decorator_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe BusinessDecorator do
+
+ before(:all) { @business = build(:business, phone: '1112223333') { |b| b.set_default_hours } }
+ subject { BusinessDecorator.new(@business) }
+
+ its(:phone_first3) { should == '111' }
+ its(:phone_second3) { should == '222' }
+ its(:phone_last4) { should == '3333' }
+
+ its(:sunday_hours_from_hour) { should == nil }
+ its(:sunday_hours_from_min) { should == nil }
+ its(:sunday_hours_from_ampm) { should == nil }
+ its(:sunday_hours_to_hour) { should == nil }
+ its(:sunday_hours_to_min) { should == nil }
+ its(:sunday_hours_to_ampm) { should == nil }
+
+ for day in %w[monday tuesday wednesday thursday friday saturday]
+ its("#{day}_hours_from_hour") { should == '09' }
+ its("#{day}_hours_from_min") { should == '00' }
+ its("#{day}_hours_from_ampm") { should == 'am' }
+ its("#{day}_hours_to_hour") { should == '05' }
+ its("#{day}_hours_to_min") { should == '00' }
+ its("#{day}_hours_to_ampm") { should == 'pm' }
+ end
+end
View
10 spec/decorators/college_decorator_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe CollegeDecorator do
+ let(:college) { build(:cornell) }
+ subject{ CollegeDecorator.new(college) }
+
+ its(:label) { should == "Cornell University Ithaca, NY 14853" }
+ its(:title){ "Cornell\nUniversity Ithaca, NY 14853" }
+ its(:type) { should == :c }
+end
View
100 spec/decorators/event_decorator_spec.rb
@@ -0,0 +1,100 @@
+require 'spec_helper'
+
+describe EventDecorator do
+ let(:start_time) { Time.utc(2011, 8, 5, 7, 30) }
+ let(:end_time) { Time.utc(2011, 8, 5, 9, 30) }
+
+ before(:all) do
+ @once_event =
+ build(:once_event,
+ :business => build(:business),
+ :start_time => start_time,
+ :end_time => end_time
+ ) { |e| e.id = 1 }
+ end
+
+ context 'date methods' do
+ subject { EventDecorator.new(@once_event) }
+
+ its(:start_time_str) { should == "2011-08-05 07:30 am" }
+ its(:start_date) { should == "08/05/2011" }
+ its(:start_time_hour) { should == "07" }
+ its(:start_time_minute) { should == "30" }
+ its(:start_time_am_pm) { should == "am" }
+ its(:end_date) { should == "08/05/2011" }
+ its(:end_time_hour) { should == "09" }
+ its(:end_time_minute) { should == "30" }
+ its(:end_time_am_pm) { should == "am" }
+ end
+
+ describe 'business_event_details' do
+
+ it 'for once event' do
+ event = EventDecorator.new(@once_event)
+
+ event.business_event_details.should == {
+ :id => @once_event.to_param,
+ :title => "one times",
+ :start => start_time.iso8601,
+ :end => end_time.iso8601,
+ :allDay => false,
+ :url => "/events/#{@once_event.id}/edit",
+ :className => 'event_type'
+ }
+ end
+
+ it 'for once event spanning two days and at night' do
+ event = build(:once_event,
+ :business => build(:business),
+ :start_time => Time.utc(2011, 8, 3, 23, 00),
+ :end_time => Time.utc(2011, 8, 4, 1, 30)
+ ) { |e| e.id = 1 }
+ event = EventDecorator.new(event)
+
+ event.business_event_details.should == {
+ :id => event.to_param,
+ :title => "one times",
+ :start => Time.utc(2011, 8, 3, 23, 00).iso8601,
+ :end => Time.utc(2011, 8, 4, 1, 30).iso8601,
+ :allDay => false,
+ :url => "/events/#{event.id}/edit",
+ :className => 'event_type'
+ }
+ end
+
+ context 'daily event' do
+ let(:event) do
+ build(:daily_event,
+ start_time: start_time,
+ end_time: end_time) { |e| e.id = 1 }
+ end
+
+ let(:decorated_event) { EventDecorator.new(event) }
+
+ it 'for first date' do
+ decorated_event.business_event_details.should == {
+ :id => event.to_param,
+ :title => "daily times",
+ :start => start_time.iso8601,
+ :end => end_time.iso8601,
+ :allDay => false,
+ :url => "/events/#{event.id}/edit",
+ :className => 'event_type'
+ }
+ end
+
+ it 'another date' do
+ decorated_event.business_event_details(event.start_time+1.day).should == {
+ :id => event.to_param,
+ :title => "daily times",
+ :start => (start_time+1.day).iso8601,
+ :end => (end_time+1.day).iso8601,
+ :allDay => false,
+ :url => "/events/#{event.id}/edit",
+ :className => 'event_type'
+ }
+ end
+ end
+
+ end
+end
View
11 spec/decorators/zip_code_decorator_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe ZipCodeDecorator do
+ let(:zip_code) { build(:ithaca) }
+ subject{ ZipCodeDecorator.new(zip_code) }
+
+ its(:zip_code) { should == zip_code.zip_code }
+ its(:full_address){ should == "Ithaca New York 14850" }
+ its(:label){ should == "Ithaca, NY 14850" }
+ its(:type) { should == :z }
+end
View
1  spec/factories/blueprints.rb
@@ -28,7 +28,6 @@
factory :business do
name { 'Dans Diner' }
association :user, :factory => :business_user
- #user { Factory.build(:business_user) }
phone { "6505551212" }
address { '1 Dude street' }
city { 'Oswego' }
View
39 spec/models/business_spec.rb
@@ -6,7 +6,7 @@ def time_hm(hour, min)
Time.utc(1970, 1, 1, hour, min)
end
- let(:business) { b = build(:oswego_cafe, :user=>nil); b.set_default_hours; b }
+ let(:business) { b = build(:oswego_cafe, :user => nil); b.set_default_hours; b }
subject { business }
it { should respond_to :sunday_hours }
@@ -18,15 +18,13 @@ def time_hm(hour, min)
it { should respond_to :saturday_hours }
context "has daily hours" do
- its(:sunday_hours) { should == {:from=>nil, :to=>nil, :open=>false} }
- its(:monday_hours) { should == {:from=>time_hm(9, 0), :to=>time_hm(17, 0), :open=>true} }
+ its(:sunday_hours) { should == {:from => nil, :to => nil, :open => false} }
+ its(:monday_hours) { should == {:from => time_hm(9, 0), :to => time_hm(17, 0), :open => true} }
end
context "can return 'to' and from' time elements for a given day" do
its(:monday_hours_from) { should == time_hm(9, 0) }
- its(:monday_hours_from_ampm) { should == "am" }
its(:saturday_hours_to) { should == time_hm(17, 0) }
- its(:saturday_hours_to_ampm) { should == "pm" }
end
context "can handle null hours on closed day" do
@@ -37,7 +35,7 @@ def time_hm(hour, min)
context "with hours set up" do
it "can set hours on day" do
- business.monday_hours_from = {'hour'=>"05", 'min'=>'12', 'ampm'=> 'am'}
+ business.monday_hours_from = {'hour' => "05", 'min' => '12', 'ampm' => 'am'}
business.monday_hours_from.should == time_hm(5, 12)
end
@@ -52,7 +50,7 @@ def time_hm(hour, min)
it "can set hours on day" do
business.monday_hours_open = true
- business.monday_hours_from = {'hour'=>"05", 'min'=>'12', 'ampm'=> 'am'}
+ business.monday_hours_from = {'hour' => "05", 'min' => '12', 'ampm' => 'am'}
business.monday_hours_from.should == time_hm(5, 12)
end
@@ -74,18 +72,19 @@ def time_hm(hour, min)
describe "makes valid model" do
before do
- @attributes = {"name"=>"yo cafe", "service_type"=>"2", "description"=>"fun cafe", "address"=>"1 Dude street", "address2"=>"",
- "city"=>"New York", "state"=>"NY", "zip_code"=>"10003",
- "phone_first3"=>"900", "phone_second3"=>"111", "phone_last4"=>"2222",
- "lat" => 1, "lng"=>1,
- "sunday_hours_from"=>{"hour"=>"00", "min"=>"00", "ampm"=>"am"}, "sunday_hours_to"=>{"hour"=>"00", "min"=>"00", "ampm"=>"am"}, "sunday_hours_open"=>"0",
- "monday_hours_from"=>{"hour"=>"05", "min"=>"15", "ampm"=>"pm"}, "monday_hours_to"=>{"hour"=>"05", "min"=>"00", "ampm"=>"pm"}, "monday_hours_open"=>"1",
- "tuesday_hours_from"=>{"hour"=>"09", "min"=>"00", "ampm"=>"am"}, "tuesday_hours_to"=>{"hour"=>"05", "min"=>"00", "ampm"=>"pm"}, "tuesday_hours_open"=>"1",
- "wednesday_hours_from"=>{"hour"=>"09", "min"=>"00", "ampm"=>"am"}, "wednesday_hours_to"=>{"hour"=>"05", "min"=>"00", "ampm"=>"pm"}, "wednesday_hours_open"=>"1",
- "thursday_hours_from"=>{"hour"=>"09", "min"=>"00", "ampm"=>"am"}, "thursday_hours_to"=>{"hour"=>"05", "min"=>"00", "ampm"=>"pm"}, "thursday_hours_open"=>"1",
- "friday_hours_from"=>{"hour"=>"09", "min"=>"00", "ampm"=>"am"}, "friday_hours_to"=>{"hour"=>"05", "min"=>"00", "ampm"=>"pm"}, "friday_hours_open"=>"1",
- "saturday_hours_from"=>{"hour"=>"09", "min"=>"00", "ampm"=>"am"}, "saturday_hours_to"=>{"hour"=>"02", "min"=>"22", "ampm"=>"am"}, "saturday_hours_open"=>"1"
- }
+ @attributes =
+ {"name" => "yo cafe", "service_type" => "2", "description" => "fun cafe", "address" => "1 Dude street", "address2" => "",
+ "city" => "New York", "state" => "NY", "zip_code" => "10003",
+ "phone_first3" => "900", "phone_second3" => "111", "phone_last4" => "2222",
+ "lat" => 1, "lng" => 1,
+ "sunday_hours_from" => {"hour" => "00", "min" => "00", "ampm" => "am"}, "sunday_hours_to" => {"hour" => "00", "min" => "00", "ampm" => "am"}, "sunday_hours_open" => "0",
+ "monday_hours_from" => {"hour" => "05", "min" => "15", "ampm" => "pm"}, "monday_hours_to" => {"hour" => "05", "min" => "00", "ampm" => "pm"}, "monday_hours_open" => "1",
+ "tuesday_hours_from" => {"hour" => "09", "min" => "00", "ampm" => "am"}, "tuesday_hours_to" => {"hour" => "05", "min" => "00", "ampm" => "pm"}, "tuesday_hours_open" => "1",
+ "wednesday_hours_from" => {"hour" => "09", "min" => "00", "ampm" => "am"}, "wednesday_hours_to" => {"hour" => "05", "min" => "00", "ampm" => "pm"}, "wednesday_hours_open" => "1",
+ "thursday_hours_from" => {"hour" => "09", "min" => "00", "ampm" => "am"}, "thursday_hours_to" => {"hour" => "05", "min" => "00", "ampm" => "pm"}, "thursday_hours_open" => "1",
+ "friday_hours_from" => {"hour" => "09", "min" => "00", "ampm" => "am"}, "friday_hours_to" => {"hour" => "05", "min" => "00", "ampm" => "pm"}, "friday_hours_open" => "1",
+ "saturday_hours_from" => {"hour" => "09", "min" => "00", "ampm" => "am"}, "saturday_hours_to" => {"hour" => "02", "min" => "22", "ampm" => "am"}, "saturday_hours_open" => "1"
+ }
end
it "from new" do
@@ -94,7 +93,7 @@ def time_hm(hour, min)
end
it "from create" do
- b = Business.create(@attributes.merge(:user_id=>1))
+ b = Business.create(@attributes.merge(:user_id => 1))
b.valid?.should == true
end
end
View
48 spec/models/event_spec.rb
@@ -46,32 +46,6 @@
end
end
- #it "#business_event_details" do
- # event.business_event_details.should == {
- # :id=> event.to_param,
- # :title=> "one times",
- # :start=> Time.utc(2011, 8, 5, 7, 30),
- # :end=> Time.utc(2011, 8, 5, 9, 30),
- # :allDay=> false,
- # :url=> "/events/#{event.id}/edit",
- # :className=> 'event_type'
- # }
- #end
- #
- #it "#business_event_details for event spanning two days and at night" do
- # event.start_time = Time.utc(2011, 8, 3, 23, 00)
- # event.end_time = Time.utc(2011, 8, 4, 1, 30)
- #
- # event.business_event_details.should == {
- # :id=>event.to_param,
- # :title=>"one times",
- # :start=>Time.utc(2011, 8, 3, 23, 00),
- # :end=>Time.utc(2011, 8, 4, 1, 30),
- # :allDay=>false,
- # :url=>"/events/#{event.id}/edit",
- # :className=> 'event_type'
- # }
- #end
end
describe "daily" do
@@ -103,28 +77,6 @@
event.occurrences_between(event.start_time, event.start_time+1.day).size.should == 2
end
- #it "#business_event_details" do
- # event.business_event_details.should == {
- # :id=>event.to_param,
- # :title=>"daily times",
- # :start=>Time.utc(2011, 8, 5, 7, 30),
- # :end=>Time.utc(2011, 8, 5, 9, 30),
- # :allDay=>false,
- # :url=>"/events/#{event.id}/edit",
- # :className=> 'event_type'
- # }
- #
- # event.business_event_details(event.start_time+1.day).should == {
- # :id=>event.to_param,
- # :title=>"daily times",
- # :start=>Time.utc(2011, 8, 6, 7, 30),
- # :end=>Time.utc(2011, 8, 6, 9, 30),
- # :allDay=>false,
- # :url=>"/events/#{event.id}/edit",
- # :className=> 'event_type'
- # }
- #end
-
describe "set until date on new schedule" do
let(:event) {
event = build(:daily_event, recur_until_date: @until_time)
Please sign in to comment.
Something went wrong with that request. Please try again.