Browse files

fix 0 hour issue when t.hour % 12 = 0

- run output from strftime through gsub
  replacing /^0/ w/ ''

cucs & specs red > green
- use page.id to build content_page links,
  instead of page.to_param, which was including
  the parameterized name, causing test failure
  • Loading branch information...
1 parent f535c88 commit a65cc722c32a7c2196adee101820197481ea38f8 @inertialbit inertialbit committed May 9, 2012
View
45 app/helpers/event_calendar/events_helper.rb
@@ -8,32 +8,32 @@ def event_one_liner(event)
].
join(" ").html_safe
end
-
+
def event_abbrev_date(event)
if event.one_day?
"(<em>#{event.start_on.strftime("%a")} #{event.start_day.ordinalize}</em>)".html_safe
else
"(<em>#{event.start_on.strftime("%a")} #{event.start_day.ordinalize} - #{event.end_on.strftime("%a")} #{event.end_day.ordinalize}</em>)".html_safe
end
end
-
+
def event_details_link(event)
path = "event_calendar_#{event.deleted? ? 'event_revision_path' : 'event_path'}"
"<span class=\"fake_button\">#{link_to('Details', send(path, event))}</span>".html_safe
end
-
+
def event_type_label(event_type)
"<span class=\"category_label #{event_type_css_class(event_type)}\">#{h(event_type)}</span>".html_safe
end
-
+
def event_type_css_class(event_type)
css_class = event_type.parameterize('_').downcase
h("#{css_class}_event")
end
-
+
def event_type_legend(wrapper_css_class, wrapper_css_style='')
return '' unless @event_types.any?
-
+
content_tag :ul, :class => "#{wrapper_css_class} legend", :style => wrapper_css_style do
@event_types.map do |event_type|
css_class = event_type_css_class(event_type)
@@ -50,11 +50,11 @@ def div_for_record(record, options={}, &block)
def tag_for_record(tag, record, *args, &block)
content_tag_for(tag, record, *args){ yield }
end
-
+
def link_wrapper(path, wrapper_options={}, link_options={})
tag = wrapper_options.delete(:tag) || :p
link_text = link_options.delete(:link_text) || path
-
+
unless wrapper_options.delete(:no_wrapper)
return content_tag(tag, wrapper_options) do
link_to(link_text, path, link_options)
@@ -63,27 +63,26 @@ def link_wrapper(path, wrapper_options={}, link_options={})
return link_to(link_text, path, link_options)
end
end
-
+
def open_if_current_month(month, closed_or_open)
# setting closed_or_open='closed' in args does not seem to work when a
# nil val is passed as the closed_or_open arg
closed_or_open = closed_or_open.blank? ? 'closed' : closed_or_open
Date.current.strftime("%B") == month ? 'open' : closed_or_open
end
-
+
def time_with_zones(time=Time.now)
out = []
ActiveSupport::TimeZone.us_zones.map(&:name).each do |us_zone|
next unless us_zone =~ /Pacific|Mountain|Central|Eastern/
key = time.in_time_zone(us_zone).strftime("%Z")
key = timezone_in_words(key.strip)
t = time.in_time_zone(us_zone)
- # this little shenanigan is for getting rid of the 0 before the hour
- out << [key, t.strftime("#{t.hour % 12}:%M %p")]
+ out << [key, t.strftime(TIME_BASE).gsub(/^0/, '')]
end
out.reverse
end
-
+
def timezone_in_words(zone)
pac_regex = /^P(S|D)T$/
mnt_regex = /^M(S|D)T$/
@@ -102,7 +101,7 @@ def timezone_in_words(zone)
zone
end
end
-
+
def event_times(event)
t = []
event_times = times_with_zones(event)
@@ -111,14 +110,14 @@ def event_times(event)
end
t.join(" / ").html_safe
end
-
+
def times_with_zones(event)
[
time_with_zones(event.start_time),
time_with_zones(event.end_time)
]
end
-
+
def hour_options
[
['6 AM','6'],
@@ -138,18 +137,18 @@ def hour_options
['8 PM','20']
]
end
-
+
def minute_options
['00', '15', '30', '45']
end
-
+
def link_to_events(wrapper_options={}, link_options={})
return unless has_authorization?(:read, EventCalendar::Event.new)
link_wrapper(event_calendar_events_path, wrapper_options, link_options.reverse_merge!({
:link_text => 'Event Calendar'
}))
end
-
+
def link_to_event_revisions(wrapper_options={}, link_options={})
return unless has_authorization?(:read, EventCalendar::EventRevision.new)
link_wrapper(event_calendar_event_revisions_path, {
@@ -188,15 +187,15 @@ def link_to_edit_event(event, wrapper_options={}, link_options={})
:link_text => "Edit <em>#{h(event.name)}</em>".html_safe
}.merge!(link_options))
end
-
+
def link_to_new_link(event, wrapper_options={}, link_options={})
return unless has_authorization?(:create, EventCalendar::Link.new)
link_wrapper(new_event_calendar_event_link_path(event), wrapper_options, {
:link_text => 'Add a new link to this event',
:class => 'fake_button'
}.merge!(link_options))
end
-
+
def link_to_edit_link(event, link, wrapper_options={}, link_options={})
return unless has_authorization?(:update, link)
link_wrapper(edit_event_calendar_event_link_path(event, link), {
@@ -205,7 +204,7 @@ def link_to_edit_link(event, link, wrapper_options={}, link_options={})
:link_text => "update"
}.merge!(link_options))
end
-
+
def link_to_delete_link(event, link, wrapper_options={}, link_options={})
return unless has_authorization?(:delete, link)
link_wrapper(event_calendar_event_link_path(event, link), {
@@ -227,7 +226,7 @@ def link_to_delete_event(event, wrapper_options={}, link_options={})
:method => "delete"
}.merge!(link_options))
end
-
+
def links_to_edit_and_delete_event(event, wrapper_options={}, link_options={})
return unless has_authorization?(:delete, event) || has_authorization?(:update, event)
link_to_edit_event(event, {
View
18 features/event_calendar.feature
@@ -29,7 +29,7 @@ Feature: Event calendar
Then I should see "Event was successfully created."
And I should see "Some implied event ending (Conference)"
And I should see "Date: Saturday, February 26 2011"
- And I should see "Time: 02:30 PM - 03:30 PM Eastern / 01:30 PM - 02:30 PM Central / 12:30 PM - 01:30 PM Mountain / 11:30 AM - 12:30 PM Pacific"
+ And I should see "Time: 2:30 PM - 3:30 PM Eastern / 1:30 PM - 2:30 PM Central / 12:30 PM - 1:30 PM Mountain / 11:30 AM - 12:30 PM Pacific"
Scenario: create a new event w/ only an explicit start date
Given I am on the new event page
@@ -40,34 +40,34 @@ Feature: Event calendar
Then I should see "Event was successfully created."
And I should see "Some implied start and end time"
And I should see "Date: Friday, March 04 2011"
- And I should see "Time: 09:00 AM - 10:00 AM Eastern / 08:00 AM - 09:00 AM Central / 07:00 AM - 08:00 AM Mountain / 06:00 AM - 07:00 AM Pacific"
+ And I should see "Time: 9:00 AM - 10:00 AM Eastern / 8:00 AM - 9:00 AM Central / 7:00 AM - 8:00 AM Mountain / 6:00 AM - 7:00 AM Pacific"
Scenario: update a multi day event
Given I am on the event page for "Editable Event"
- And I follow "update" within "div.event_calendar_event"
+ And I follow "Edit this Event" within "#admin_bar"
And I fill in "Name" with "Updated Event"
And I press "Update Event"
Then I should see "Event was successfully updated."
Scenario: update a single day event
Given I am on the event page for "Linkable Event"
- And I follow "update" within "div.event_calendar_event"
+ And I follow "Edit this Event" within "#admin_bar"
And I fill in "Start date" with "02/23/2011"
And I fill in "End date" with "02/23/2011"
And I select "Pacific Time (US & Canada)" from "Timezone"
And I press "Update Event"
Then I should be on the event page for "Linkable Event"
- And I should see "Time: 09:00 AM - 10:00 AM Eastern / 08:00 AM - 09:00 AM Central / 07:00 AM - 08:00 AM Mountain / 06:00 AM - 07:00 AM Pacific"
+ And I should see "Time: 9:00 AM - 10:00 AM Eastern / 8:00 AM - 9:00 AM Central / 7:00 AM - 8:00 AM Mountain / 6:00 AM - 7:00 AM Pacific"
Scenario: delete an event
Given I am on the event page for "Editable Event"
- And I follow "delete" within "div.event_calendar_event"
+ And I follow "Delete this Event" within "#admin_bar"
Then I should be on the events page
Scenario: deleting then restoring an event
Given I am on the event page for "Restorable Event"
- Then I should see "Time: 09:00 AM - 10:00 AM Eastern / 08:00 AM - 09:00 AM Central / 07:00 AM - 08:00 AM Mountain / 06:00 AM - 07:00 AM Pacific"
- And I follow "delete"
+ Then I should see "Time: 9:00 AM - 10:00 AM Eastern / 8:00 AM - 9:00 AM Central / 7:00 AM - 8:00 AM Mountain / 6:00 AM - 7:00 AM Pacific"
+ And I follow "Delete this Event" within "#admin_bar"
Then I should be on the events page
When I go to the manage events page
And I follow "Browse Deleted Events"
@@ -79,4 +79,4 @@ Feature: Event calendar
When I follow "restore"
Then I should be on the event page for "Restorable Event"
And I should see "Date: Friday, February 04 2011"
- And I should see "Time: 09:00 AM - 10:00 AM Eastern / 08:00 AM - 09:00 AM Central / 07:00 AM - 08:00 AM Mountain / 06:00 AM - 07:00 AM Pacific"
+ And I should see "Time: 9:00 AM - 10:00 AM Eastern / 8:00 AM - 9:00 AM Central / 7:00 AM - 8:00 AM Mountain / 6:00 AM - 7:00 AM Pacific"
View
10 features/read_blog_content.feature
@@ -2,22 +2,22 @@ Feature: Read blog content
In order to learn new stuff and kill time
As a random user
I want to navigate and consume blog content in various ways
-
+
Background: anonymous user is reading blog posts
Given I am on the blog posts page
-
+
Scenario: read a blog post
Then I should see "Some Great Title"
And I should see "The body for Some Great Title"
- When I follow "Read more..." within "div.posts div:nth-child(2)"
+ When I follow "Read more..." within "div.posts > div:nth-of-type(3)"
Then I should be on the blog post page for "Some Great Title"
-
+
Scenario: view all blog posts by a specific author
When I follow "John Doe"
Then I should be on the blog posts by "John Doe" page
And I should not see "Some Other Title"
And I should see "Some Great Title"
-
+
Scenario: easily view sibling sub-categories of currently selected category
When I have and follow "Top Level Category"
Then I should see all the posts in the category "Top Level Category"
View
44 lib/html_generator.rb
@@ -21,9 +21,9 @@ def list_categories_to_html(options = {})
if cat.children.empty? and cat.content_pages.count == 0
"<li class=\"category_#{cat.id}\"><a href=\"/categories/#{cat.id}\">#{cat.name}</a></li>"
else
- "<li class=\"category_#{cat.id}\">" +
- main_menu_link("/categories/#{cat.id}", cat.name, "cat_menu_#{cat.id}") +
- "<div class=\"mega_menu cat_menu_#{cat.id} menu_hidable\" style=\"display:none;\">" +
+ "<li class=\"category_#{cat.id}\">" +
+ main_menu_link("/categories/#{cat.id}", cat.name, "cat_menu_#{cat.id}") +
+ "<div class=\"mega_menu cat_menu_#{cat.id} menu_hidable\" style=\"display:none;\">" +
(cat.content_pages.count == 0 ? '' : "<h4>#{cat.name}</h4>") +
list_pages_in_category_to_html(:category => cat, :cascade => options[:cascade]) +
"</div>" +
@@ -80,10 +80,10 @@ def list_pages_in_category_to_html(options = {})
"<li><a href=\"/content_pages/#{page.id}\">#{page.name}</a></li>"
}.join("")
unless category.children.empty?
- category.children.each do |cat|
- out += "<li><h5><a class=\"menu_show_hide_link\" href=\"/categories/#{cat.id}?toggle=cat_menu_#{cat.id}&hide=inner_menu\">#{cat.name}</a></h5></li>"
+ category.children.each do |cat|
+ out += "<li><h5><a class=\"menu_show_hide_link\" href=\"/categories/#{cat.id}?toggle=cat_menu_#{cat.id}&hide=inner_menu\">#{cat.name}</a></h5></li>"
out += "<div style=\"display:none;\" class=\"cat_menu_#{cat.id} inner_menu\">" if options[:cascade]
- out += list_pages_in_category_to_html(:category => cat, :cascade => options[:cascade])
+ out += list_pages_in_category_to_html(:category => cat, :cascade => options[:cascade])
out += "</div>" if options[:cascade]
end
end
@@ -95,7 +95,7 @@ def list_pages_in_category_to_html(options = {})
out += "</ul>"
out
end
- alias_method :listpagesincategory_to_html, :list_pages_in_category_to_html
+ alias_method :listpagesincategory_to_html, :list_pages_in_category_to_html
def tree_categories_to_html(options = {})
categories = \
@@ -137,7 +137,7 @@ def link_page_to_html(options={})
page = ContentPage.find_by_name page_name
if page
- "<a href=\"/content_pages/#{page.to_param}\">#{page.name}</a>"
+ "<a href=\"/content_pages/#{page.id}\">#{page.name}</a>"
else
"<em>No page found named: #{page_name}</em>"
end
@@ -160,7 +160,7 @@ def link_category_to_html(options={})
def all_recent_message_posts_to_html(options = {})
# TODO: maybe set this up to poll every few minutes
id = options[:id] ||= "all_recent_messages"
-
+
<<-END
<div id="#{id}" class="recent_messages_box">
<em>please log in to view recent messages from the forums</em>
@@ -180,7 +180,7 @@ def recent_message_posts_to_html(options = {})
id = options[:id] ||= "recent_messages"
forum_title = options[:other_params]
forum = Forum.find_by_title(forum_title)
-
+
<<-END
<div id="#{id}" class="recent_messages_box">
<em>please log in to view recent messages from the forums</em>
@@ -197,7 +197,7 @@ def recent_message_posts_to_html(options = {})
def recent_wiki_comments_to_html(options = {})
# TODO: maybe set this up to poll every few minutes
id = options[:id] ||= "recent_wiki_comments"
-
+
<<-END
<div id="#{id}" class="recent_messages_box">
<em>please log in to view recent wiki activity</em>
@@ -225,17 +225,17 @@ def search_box_to_html(options = {})
def mini_calendar_to_html(options={})
#TODO - make options for changing id of calendar element
- <<-END
+ <<-END
<link href="/stylesheets/minical.css" media="screen, projection" rel="stylesheet" type="text/css" />
<div id="minicalendar" class="calendars"></div>
<script type="text/javascript">
$(document).ready(function() {
- $('#minicalendar').fullCalendar({
+ $('#minicalendar').fullCalendar({
header: { left: 'prev', right: 'next', center: 'title' },
- editable: false,
- events: '/event_calendar/events',
+ editable: false,
+ events: '/event_calendar/events',
eventMouseover: function(event, jsEvent, view) {
$(jsEvent.target).attr('title', event.title);
}
@@ -249,7 +249,7 @@ def mini_calendar_to_html(options={})
def calendar_to_html(options={})
options[:height] ||= 500
#TODO - make options for changing id of calendar element
- <<-END
+ <<-END
<div id="calendar" class="calendars"></div>
<div style="clear:both"></div>
@@ -258,11 +258,11 @@ def calendar_to_html(options={})
<script type="text/javascript">
$(document).ready(function() {
- $('#calendar').fullCalendar({
+ $('#calendar').fullCalendar({
header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' },
- editable: false,
- events: '/event_calendar/events',
- height: #{options[:height]},
+ editable: false,
+ events: '/event_calendar/events',
+ height: #{options[:height]},
aspectRatio: 1,
eventMouseover: updateEventDescription
});
@@ -284,8 +284,8 @@ def bloglink
"<li class=\"bloglink\"><a href=\"/blog\">#{SiteSetting.read_or_write_default_setting('blog title','Blog')}</a></li>"
end
- def main_menu_link(base_url, link_text, menu_css_class, menu_id = nil)
- "<a href=\"#{base_url}?toggle=#{menu_css_class}&hide=menu_hidable\" " +
+ def main_menu_link(base_url, link_text, menu_css_class, menu_id = nil)
+ "<a href=\"#{base_url}?toggle=#{menu_css_class}&hide=menu_hidable\" " +
"class=\"menu_show_hide_link\" id=\"#{menu_id}\">#{link_text}</a>"
end
View
4 spec/controllers/forums_controller_spec.rb
@@ -14,7 +14,7 @@ def mock_forum(stubs={})
def mock_message_post(stubs={})
@mock_message_post ||= mock_model(MessagePost, stubs.merge({}))
end
-
+
def mock_message_posts
return @mock_message_posts if @mock_message_posts
@mock_message_posts = mock('message_posts_proxy')
@@ -80,7 +80,7 @@ def mock_message_posts
it "redirects to the created forum" do
Forum.stub!(:new).and_return(mock_forum(:save => true))
post :create, :forum => {}
- response.should redirect_to(forums_url)
+ response.should redirect_to(edit_forum_path(mock_forum))
end
end
View
10 spec/helpers/event_calendar/events_helper_spec.rb
@@ -5,14 +5,14 @@
it "returns times" do
time = Time.now
helper.time_with_zones(time).should eq [
- ["Eastern", time.in_time_zone("Eastern Time (US & Canada)").strftime(TIME_BASE)],
- ["Central", time.in_time_zone("Central Time (US & Canada)").strftime(TIME_BASE)],
- ["Mountain", time.in_time_zone("Mountain Time (US & Canada)").strftime(TIME_BASE)],
- ["Pacific", time.in_time_zone("Pacific Time (US & Canada)").strftime(TIME_BASE)]
+ ["Eastern", time.in_time_zone("Eastern Time (US & Canada)").strftime(TIME_BASE).gsub(/^0/, '')],
+ ["Central", time.in_time_zone("Central Time (US & Canada)").strftime(TIME_BASE).gsub(/^0/, '')],
+ ["Mountain", time.in_time_zone("Mountain Time (US & Canada)").strftime(TIME_BASE).gsub(/^0/, '')],
+ ["Pacific", time.in_time_zone("Pacific Time (US & Canada)").strftime(TIME_BASE).gsub(/^0/, '')]
]
end
end
-
+
describe "open_if_current_month..." do
let(:month_names) do
%w(January February March April May June July August September October
View
14 spec/libs/html_generator_spec.rb
@@ -179,18 +179,18 @@ class DummyClass
it "should work for a plain calendar" do
expected = <<-END
<div id="calendar" class="calendars"></div>
-
+
<div style="clear:both"></div>
-
+
<div id="event_quick_description" style="display:none"></div>
-
+
<script type="text/javascript">
$(document).ready(function() {
- $('#calendar').fullCalendar({
+ $('#calendar').fullCalendar({
header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' },
- editable: false,
- events: '/event_calendar/events',
- height: 500,
+ editable: false,
+ events: '/event_calendar/events',
+ height: 500,
aspectRatio: 1,
eventMouseover: updateEventDescription
});
View
20 spec/models/file_attachment_spec.rb
@@ -6,7 +6,7 @@
module Blog; class Post; extend ActiveModel::Naming; def self.base_class; Blog::Post; end end end
class Event; extend ActiveModel::Naming; def self.base_class; Event; end end
-
+
before(:each) do
# File.stub(:open)
@path = File.join(Rails.root.to_s, 'public', 'files', 'general')
@@ -23,13 +23,15 @@ class Event; extend ActiveModel::Naming; def self.base_class; Event; end end
after(:each) do
FileUtils.rm_f(@full_path)
+ @file_attachment.uploaded_file = nil
+ @file_attachment.save! unless @file_attachment.frozen?
end
context "generating a unique filename" do
before(:each) do
@new_file = FileAttachment.new({
:description => 'other description',
- :uploaded_file => @somefile
+ :uploaded_file => @somefile
})
end
it "should generate a unique name on create" do
@@ -39,32 +41,32 @@ class Event; extend ActiveModel::Naming; def self.base_class; Event; end end
File.should_receive(:open).with("#{@path}/somefile-1.txt", "wb").at_least(:once)
@new_file.save
end
- it "should not generate a unique name on update" do
+ it "should not generate a unique name on update" do
@new_file.save
@new_file.should_not_receive(:generate_unique_filename)
@new_file.save
end
end
-
+
it "should know whether its file actually exists" do
File.stub(:exists?).with("#{@path}/somefile.txt"){ true }
@file_attachment.file_saved?.should be_true
File.stub(:exists?).with("#{@path}/somefile.txt"){ false }
@file_attachment.file_saved?.should be_false
end
-
+
it "should move its file to the trash when destroyed" do
@file_attachment.should_receive(:move_file_to_trash_folder!)
@file_attachment.destroy
end
-
+
it "should know how to throw files into the trash" do
@file_attachment.stub(:generate_unique_filename){ "somefile.txt" }
File.stub(:exists?){ true }
FileUtils.should_receive(:mv).with(@full_path, @trash_path)
@file_attachment.send(:move_file_to_trash_folder!)
end
-
+
context "determine storage path" do
it "uses public/files/general without an attachable" do
@file_attachment.send(:attachable_folder).should eq "general"
@@ -85,12 +87,12 @@ class Event; extend ActiveModel::Naming; def self.base_class; Event; end end
@file_attachment.filepath.should eq "public/files/event/#{event.id}/somefile.txt"
end
end
-
+
it "should ensure that the destination folder exists" do
FileUtils.should_receive(:mkdir_p).with(@path)
@file_attachment.send(:ensure_folder_path_exists)
end
-
+
context "should be able to update filepath in db & fs" do
before(:each) do
@old_path = File.join "public", "files", "somefile.txt"
View
6 spec/models/file_container_spec.rb
@@ -5,16 +5,16 @@
end
describe FileContainer do
-
+
before(:each) do
build_model :mock_container do
string :name
end
end
-
+
it "collects including class names" do
MockContainer.send :include, FileContainer
- FileContainer.types.should eql [MockContainer]
+ FileContainer.types.should include MockContainer
end
it "declares the has_many side of attachable <> file_attachment assoc." do
MockContainer.should_receive(:has_many)

0 comments on commit a65cc72

Please sign in to comment.