diff --git a/app/controllers/public/events_controller.rb b/app/controllers/public/events_controller.rb
index 5139a19..749d7d8 100644
--- a/app/controllers/public/events_controller.rb
+++ b/app/controllers/public/events_controller.rb
@@ -1,29 +1,30 @@
class EventsController < PublicController
needs_profile
- no_design_blocks
def events
- @selected_day = nil
- @events_of_the_day = []
- date = build_date(params[:year], params[:month], params[:day])
+ @events = []
+ @date = build_date(params[:year], params[:month], params[:day])
- if params[:day] || !params[:year] && !params[:month]
- @selected_day = date
- @events_of_the_day = profile.events.by_day(@selected_day)
+ if !params[:year] && !params[:month] && !params[:day]
+ @events = profile.events.next_events_from_month(@date)
end
- events = profile.events.by_range((date - 1.month).at_beginning_of_month..(date + 1.month).at_end_of_month)
+ if params[:year] || params[:month]
+ @events = profile.events.by_month(@date)
+ end
+
+ events_in_range = profile.events.by_range((@date - 1.month).at_beginning_of_month .. (@date + 1.month).at_end_of_month)
- @calendar = populate_calendar(date, events)
- @previous_calendar = populate_calendar(date - 1.month, events)
- @next_calendar = populate_calendar(date + 1.month, events)
+ @calendar = populate_calendar(@date, events_in_range)
+ @previous_calendar = populate_calendar(@date - 1.month, events_in_range)
+ @next_calendar = populate_calendar(@date + 1.month, events_in_range)
end
def events_by_day
- @selected_day = build_date(params[:year], params[:month], params[:day])
- @events_of_the_day = profile.events.by_day(@selected_day)
- render :partial => 'events_by_day'
+ @date = build_date(params[:year], params[:month], params[:day])
+ @events = profile.events.by_day(@date)
+ render :partial => 'events'
end
protected
diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb
index 8ce8bd7..f38f243 100644
--- a/app/controllers/public/search_controller.rb
+++ b/app/controllers/public/search_controller.rb
@@ -93,25 +93,29 @@ class SearchController < PublicController
year = (params[:year] ? params[:year].to_i : Date.today.year)
month = (params[:month] ? params[:month].to_i : Date.today.month)
day = (params[:day] ? params[:day].to_i : Date.today.day)
- date = build_date(params[:year], params[:month], params[:day])
- date_range = (date - 1.month).at_beginning_of_month..(date + 1.month).at_end_of_month
+ @date = build_date(year, month, day)
+ date_range = (@date - 1.month).at_beginning_of_month..(@date + 1.month).at_end_of_month
- @selected_day = nil
- @events_of_the_day = []
+ @events = []
if params[:day] || !params[:year] && !params[:month]
- @selected_day = date
- @events_of_the_day = @category ?
- environment.events.by_day(@selected_day).in_category(Category.find(@category_id)) :
- environment.events.by_day(@selected_day)
+ @events = @category ?
+ environment.events.by_day(@date).in_category(Category.find(@category_id)) :
+ environment.events.by_day(@date)
+ end
+
+ if params[:year] || params[:month]
+ @events = @category ?
+ environment.events.by_month(@date).in_category(Category.find(@category_id)) :
+ environment.events.by_month(@date)
end
@scope = date_range && params[:action] == 'events' ? environment.events.by_range(date_range) : environment.events
full_text_search
events = @searches[@asset][:results]
- @calendar = populate_calendar(date, events)
- @previous_calendar = populate_calendar(date - 1.month, events)
- @next_calendar = populate_calendar(date + 1.month, events)
+ @calendar = populate_calendar(@date, events)
+ @previous_calendar = populate_calendar(@date - 1.month, events)
+ @next_calendar = populate_calendar(@date + 1.month, events)
end
# keep old URLs workings
@@ -136,9 +140,9 @@ class SearchController < PublicController
end
def events_by_day
- @selected_day = build_date(params[:year], params[:month], params[:day])
- @events_of_the_day = environment.events.by_day(@selected_day)
- render :partial => 'events/events_by_day'
+ @date = build_date(params[:year], params[:month], params[:day])
+ @events = environment.events.by_day(@date)
+ render :partial => 'events/events'
end
#######################################################
diff --git a/app/helpers/dates_helper.rb b/app/helpers/dates_helper.rb
index 57dc611..77300e4 100644
--- a/app/helpers/dates_helper.rb
+++ b/app/helpers/dates_helper.rb
@@ -35,6 +35,18 @@ module DatesHelper
end
end
+ def show_date_month(date, use_numbers = false, year=true)
+ if date && use_numbers
+ date_format = year ? _('%{month}/%{year}') : _('%{month}/%{day}')
+ date_format % { :month => date.month, :year => date.year }
+ elsif date
+ date_format = year ? _('%{month_name}, %{year}') : _('%{month_name}')
+ date_format % { :month_name => month_name(date.month), :year => date.year }
+ else
+ ''
+ end
+ end
+
# formats a datetime for displaying.
def show_time(time)
if time
@@ -98,7 +110,11 @@ module DatesHelper
elsif opts[:previous]
date = date << 1
end
- _('%{month} %{year}') % { :year => date.year, :month => month_name(date.month.to_i) }
+ if opts[:only_month]
+ _('%{month}') % {:month => month_name(date.month.to_i) }
+ else
+ _('%{month} %{year}') % { :year => date.year, :month => month_name(date.month.to_i) }
+ end
end
def build_date(year, month, day = 1)
@@ -123,7 +139,7 @@ module DatesHelper
previous_month_date = date - 1.month
label ||= show_month(previous_month_date.year, previous_month_date.month)
- link_to label, :year => previous_month_date.year, :month => previous_month_date.month
+ link_to label, {:year => previous_month_date.year, :month => previous_month_date.month}, {:class => 'button icon-back with-text'}
end
def link_to_next_month(year, month, label = nil)
@@ -131,7 +147,7 @@ module DatesHelper
next_month_date = date + 1.month
label ||= show_month(next_month_date.year, next_month_date.month)
- link_to label, :year => next_month_date.year, :month => next_month_date.month
+ link_to label, {:year => next_month_date.year, :month => next_month_date.month}, {:class => 'button icon-next with-text'}
end
def pick_date(object, method, options = {}, html_options = {})
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb
index 2cef85d..3b66568 100644
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -1,22 +1,24 @@
module EventsHelper
def list_events(date, events)
- return content_tag('em', _("Select a day on the left to display it's events here"), :class => 'select-a-day') unless date
- title = _('Events for %s') % show_date(date)
+ title = _('Events for %s') % show_date_month(date)
content_tag('h2', title) +
content_tag('div',
(events.any? ?
content_tag('table', events.select { |item| item.display_to?(user) }.map {|item| display_event_in_listing(item)}.join('')) :
- content_tag('em', _('No events for this date'), :class => 'no-events')
+ content_tag('em', _('No events for this month'), :class => 'no-events')
), :id => 'agenda-items'
)
end
def display_event_in_listing(article)
- content_tag(
- 'tr',
- content_tag('td', link_to(article.name, article.url, :class => icon_for_article(article))),
- :class => 'agenda-item'
+
+ content_tag( 'tr',
+ content_tag('td',
+ content_tag('div', show_date(article.start_date) + ( article.end_date.nil? ? '' : (_(" to ") + show_date(article.end_date))),:class => 'event-date' ) +
+ content_tag('div',link_to(article.name,article.url),:class => 'event-title') +
+ content_tag('div',(article.address.nil? or article.address == '') ? '' : (_('Place: ') + article.address),:class => 'event-place')
+ )
)
end
diff --git a/app/models/event.rb b/app/models/event.rb
index 712a4cd..9caece2 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -29,8 +29,29 @@ class Event < Article
end
end
- named_scope :by_day, lambda { |date|
- {:conditions => ['start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date}]}
+named_scope :by_day, lambda { |date|
+ {
+ :conditions => ['start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date}],
+ :order => 'start_date ASC'
+ }
+ }
+
+named_scope :next_events_from_month, lambda { |date|
+ date_temp = date.strftime("%Y-%m-%d")
+ {
+ :conditions => ["start_date >= ?","#{date_temp}"],
+ :limit => 10,
+ :order => 'start_date ASC'
+ }
+ }
+
+named_scope :by_month, lambda { |date|
+ date_temp = date.strftime("%Y-%m")
+ {
+ :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month],
+ :limit => 10,
+ :order => 'start_date ASC'
+ }
}
include WhiteListFilter
@@ -105,7 +126,7 @@ class Event < Article
# TODO: some good soul, please clean this ugly hack:
if self.body
- html.div('_____XXXX_DESCRIPTION_GOES_HERE_XXXX_____', :class => 'event-description')
+ html.div('_____XXXX_DESCRIPTION_GOES_HERE_XXXX_____', :class => 'event-description')
end
}
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 525df3d..5d69ea8 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -193,7 +193,7 @@ class Profile < ActiveRecord::Base
has_many :tasks, :dependent => :destroy, :as => 'target'
- has_many :events, :source => 'articles', :class_name => 'Event', :order => 'name'
+ has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date'
def find_in_all_tasks(task_id)
begin
diff --git a/app/views/events/_agenda.rhtml b/app/views/events/_agenda.rhtml
index 93b95d1..b32a04f 100644
--- a/app/views/events/_agenda.rhtml
+++ b/app/views/events/_agenda.rhtml
@@ -3,22 +3,14 @@
<%= show_month(params[:year], params[:month]) %>
- <%= link_to_previous_month(params[:year], params[:month], '« %s' % _('previous')) %>
- <%= link_to_next_month(params[:year], params[:month], '%s »' % _('next')) %>
+ <%= link_to_previous_month(params[:year], params[:month], show_month(params[:year], params[:month], :previous => true, :only_month => true)) %>
+ <%= link_to_next_month(params[:year], params[:month], show_month(params[:year], params[:month], :next => true, :only_month => true)) %>
<%= render :partial => 'events/month', :locals => {:calendar => @calendar, :abbreviated => true} %>
-
- <%= link_to_previous_month(params[:year], params[:month], show_month(params[:year], params[:month], :previous => true)) %>
- <%= render :partial => 'events/month', :locals => {:calendar => @previous_calendar, :abbreviated => true} %>
-
-
- <%= link_to_next_month(params[:year], params[:month], show_month(params[:year], params[:month], :next => true)) %>
- <%= render :partial => 'events/month', :locals => {:calendar => @next_calendar, :abbreviated => true} %>
-
- <%= render :partial => 'events/events_by_day' %>
+ <%= render :partial => 'events/events' %>
diff --git a/app/views/events/_events.rhtml b/app/views/events/_events.rhtml
new file mode 100644
index 0000000..d29736e
--- /dev/null
+++ b/app/views/events/_events.rhtml
@@ -0,0 +1 @@
+<%= list_events(@date, @events) %>
\ No newline at end of file
diff --git a/app/views/events/_events_by_day.rhtml b/app/views/events/_events_by_day.rhtml
deleted file mode 100644
index e8b37c6..0000000
--- a/app/views/events/_events_by_day.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-<%= list_events(@selected_day, @events_of_the_day) %>
diff --git a/config/routes.rb b/config/routes.rb
index 27ff0e4..fa98554 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -55,6 +55,7 @@ ActionController::Routing::Routes.draw do |map|
# events
map.events 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format}/
+ map.events 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format}/
map.events 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format}/
map.events 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format}/
map.events 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format}/
diff --git a/features/events.feature b/features/events.feature
index cf0e95e..269fbc0 100644
--- a/features/events.feature
+++ b/features/events.feature
@@ -12,43 +12,38 @@ Feature: events
Scenario: go to next month
Given I am on /profile/josesilva/events/2009/10
- When I follow "next »"
+ When I follow "November"
Then I should see "November 2009" within ".current-month"
Scenario: go to next month in global agenda
Given I am on /assets/events?year=2009&month=11
- When I follow "next »"
+ When I follow "December"
Then I should see "December 2009" within ".current-month"
Scenario: go to previous month
Given I am on /profile/josesilva/events/2009/10
- When I follow "« previous"
+ When I follow "September"
Then I should see "September 2009" within ".current-month"
Scenario: go to previous month in global agenda
Given I am on /assets/events?year=2009&month=11
- When I follow "« previous"
+ When I follow "October"
Then I should see "October 2009" within ".current-month"
Scenario: go to next month by clicking in month name
Given I am on /profile/josesilva/events/2009/10
- When I follow "November 2009"
+ When I follow "November"
Then I should see "November 2009" within ".current-month"
Scenario: go to previous month by clicking in month name
Given I am on /profile/josesilva/events/2009/10
- When I follow "September 2009"
+ When I follow "September"
Then I should see "September 2009" within ".current-month"
- Scenario: go to specific day
- Given I am on the homepage
- When I am on /profile/josesilva/events/2009/01/20
- Then I should see "Events for January 20, 2009"
-
Scenario: go to specific day in global agenda
Given I am on the homepage
When I am on /assets/events?year=2009&month=11&day=12
- Then I should see "Events for November 12, 2009"
+ Then I should see "Events for November, 2009"
Scenario: list events for specific day
Given I am on /profile/josesilva/events/2009/10
@@ -64,7 +59,7 @@ Feature: events
| owner | name | start_date |
| josesilva | WikiSym 2009 | 2009-10-25 |
When I am on /profile/josesilva/events/2009/10/20
- Then I should not see "WikiSym 2009"
+ Then I should see "WikiSym 2009"
Scenario: list event between a range
Given I am on /profile/josesilva/events/2009/10
@@ -96,20 +91,11 @@ Feature: events
Then I should see "Another Conference"
And I should see "Manuel Birthday"
- Scenario: ask for a day when no inform complete date
- When I am on /profile/josesilva/events/2009/5
- Then I should see "Select a day on the left to display it's events here"
-
- Scenario: ask for a day when no inform complete date in global agenda
- When I am on /assets/events?year=2009&month=5
- Then I should see "Select a day on the left to display it's events here"
-
+ @selenium
Scenario: provide links to days with events
Given I am on /profile/josesilva/events/2009/10
Then I should see "24" link
- When I follow "next »"
- Then I should see "24" link
- When I follow "next »"
+ When I follow "November"
Then I should not see "24" link
Scenario: provide links to all days between start and end date
@@ -128,7 +114,7 @@ Feature: events
@selenium
Scenario: show events when i follow a specific day
Given I am on /profile/josesilva/events/2009/10
- And I should not see "Another Conference"
+ And I should see "Another Conference"
When I follow "24"
Then I should see "Another Conference"
@@ -138,7 +124,7 @@ Feature: events
| owner | name | start_date | end_date |
| josesilva | YAPC::Brasil 2010 | 2010-10-30 | 2010-11-01 |
And I am on /profile/josesilva/events/2010/10
- And I should not see "YAPC::Brasil 2010"
+ And I should see "YAPC::Brasil 2010"
When I follow "31"
Then I should see "YAPC::Brasil 2010"
@@ -150,10 +136,6 @@ Feature: events
When I follow "Back to josesilva"
Then I should be on josesilva's homepage
- Scenario: warn when there is no events
- When I am on /profile/josesilva/events/2020/12/1
- Then I should see "No events for this date"
-
Scenario: provide button to create new event
Given I am logged in as "josesilva"
When I am on /profile/josesilva/events/2020/12/1
@@ -230,3 +212,35 @@ Feature: events
Then I should see "Leaded event"
And I should see "This is the abstract."
And I should not see "This is the real text."
+
+ Scenario: show range date of event
+ Given I am on /profile/josesilva/events/2009/10
+ And the following events
+ | owner | name | start_date | end_date |
+ | josesilva | WikiSym 2009 | 2009-10-25 | 2009-10-27 |
+ When I am on /profile/josesilva/events/2009/10/26
+ Then I should see "October 25, 2009 to October 27, 2009"
+
+ Scenario: show place of the event
+ Given I am on /profile/josesilva/events/2009/10
+ And the following events
+ | owner | name | start_date | end_date | address |
+ | josesilva | WikiSym 2009 | 2009-10-25 | 2009-10-27 | Earth Planet |
+ When I am on /profile/josesilva/events/2009/10/26
+ Then I should see "Place: Earth Planet"
+
+ Scenario: show event name as link
+ Given the following events
+ | owner | name | start_date |
+ | josesilva | Unpublished event | 2009-10-25 |
+ And I am logged in as "josesilva"
+ When I am on /profile/josesilva/events/2009/10/25
+ Then I should see "Unpublished event" link
+
+ Scenario: go to event page
+ Given the following events
+ | owner | name | start_date |
+ | josesilva | Oktoberfest | 2009-10-25 |
+ Given I am on /profile/josesilva/events/2009/10
+ When I follow "Oktoberfest"
+ Then I should see "Oktoberfest"
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index 765a260..662e63c 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -1,4 +1,3 @@
-require 'noosfero'
include ActionView::Helpers::AssetTagHelper
class Noosfero::Plugin
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 3bc1d4c..18c58b6 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -216,9 +216,7 @@ th {
font-weight: bold;
border-bottom: 2px solid black;
}
-td {
- border-bottom: 1px solid #e0e0e0;
-}
+
tr:hover td {
background-color: #f0f0f0;
}
@@ -301,24 +299,29 @@ div.pending-tasks {
}
/* sitemap and agenda */
+
.agenda-item a.icon, .sitemap-item a.icon {
- background-repeat: no-repeat;
- padding-left: 20px;
+ background-image: none;
+ line-height: 150%;
}
.agenda-item .icon:hover, .sitemap-item .icon:hover {
background-color: transparent;
+ text-decoration: underline;
}
-.sitemap-item a:link, .agenda-item a:link, .sitemap-item a:visited, .agenda-item a:visited {
+.agenda-item a, a:visited{
+ font-weight: bold;
+ color: black;
+}
+
+.sitemap-item a:link, .agenda-item a:link, .sitemap-item a:visited, .agenda-item a:visited, .agenda a:hover {
border: none;
text-decoration: none;
}
+
.sitemap-item img, .agenda-item img {
border: none;
}
-.sitemap-item a:hover, .agenda-item a:hover {
- color: red;
- text-decoration: underline;
-}
+
.last-update {
font-size: 12px;
}
@@ -382,7 +385,7 @@ div.pending-tasks {
font-size: 11px;
}
#category-ajax-selector .select-subcategory-link:hover {
- background-color: #FFA;
+ background-color: black;
}
#category-ajax-selector .button {
display: block;
@@ -3507,18 +3510,19 @@ div#article-parent {
width: 50%;
}
#agenda td, #agenda th {
- padding: 0px;
+ padding: 15px;
+ padding-right: 0px;
}
#agenda .agenda-calendar .previous-month td, #agenda .agenda-calendar .previous-month th, #agenda .agenda-calendar .next-month td, #agenda .agenda-calendar .next-month th {
- font-size: 10px;
- color: gray;
+ font-size: 12px;
+ color: black;
}
#agenda .agenda-calendar .current-month td {
}
#agenda .agenda-calendar .calendar-day {
}
#agenda .agenda-calendar .calendar-day-out {
- color: gray;
+ color: black;
}
#agenda .agenda-calendar .calendar-day-out span {
display: none;
@@ -3535,7 +3539,7 @@ div#article-parent {
}
#agenda .agenda-calendar .current-month {
height: 250px;
- border-bottom: 1px solid #BFC2BC;
+ border-bottom: 1px solid black;
}
#agenda .agenda-calendar .previous-month, #agenda .agenda-calendar .next-month {
float: left;
@@ -3572,14 +3576,15 @@ div#article-parent {
width: 45%;
top: 0px;
height: 100%;
- border-left: 1px solid #BFC2BC;
padding-left: 20px;
}
#agenda #events-of-the-day #agenda-items {
display: block;
overflow: auto;
overflow-x: hidden;
- height: 90%;
+ height: 80%;
+ background: white;
+ border: none;
}
#agenda-toolbar {
float: right;
@@ -3589,6 +3594,11 @@ div#article-parent {
h1#agenda-title {
position: relative;
}
+#agenda .agenda-calendar .button.icon-next.with-text {
+ background-position: right;
+ padding-left: 3px;
+ padding-right: 20px;
+}
#agenda-toolbar a.button {
border: none;
opacity: 0.6;
diff --git a/test/functional/events_controller_test.rb b/test/functional/events_controller_test.rb
index c503a35..4aac7ee 100644
--- a/test/functional/events_controller_test.rb
+++ b/test/functional/events_controller_test.rb
@@ -7,11 +7,6 @@ class EventsControllerTest < ActionController::TestCase
end
attr_reader :profile
- should 'hide sideboxes when show calendar' do
- get :events, :profile => profile.identifier
- assert_no_tag :tag => 'div', :attributes => {:id => 'boxes'}
- end
-
should 'list today events by default' do
profile.events << Event.new(:name => 'Joao Birthday', :start_date => Date.today)
profile.events << Event.new(:name => 'Maria Birthday', :start_date => Date.today)
@@ -32,27 +27,15 @@ class EventsControllerTest < ActionController::TestCase
assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /#{month}/}
end
- should 'display calendar of previous month' do
- get :events, :profile => profile.identifier
-
- month = (Date.today << 1).strftime("%B %Y")
- assert_tag :tag => 'table', :attributes => {:class => /previous-month/}, :descendant => {:tag => 'caption', :content => /#{month}/}
- end
-
- should 'display calendar of next month' do
- get :events, :profile => profile.identifier
-
- month = (Date.today >> 1).strftime("%B %Y")
- assert_tag :tag => 'table', :attributes => {:class => /next-month/}, :descendant => {:tag => 'caption', :content => /#{month}/}
- end
-
should 'display links to previous and next month' do
get :events, :profile => profile.identifier
- prev_month = Date.today << 1
- next_month = Date.today >> 1
- assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{next_month.year}/#{next_month.month}"}, :content => /next/
- assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{prev_month.year}/#{prev_month.month}"}, :content => /previous/
+ prev_month = Date.today - 1.month
+ next_month = Date.today + 1.month
+ prev_month_name = prev_month.strftime("%B")
+ next_month_name = next_month.strftime("%B")
+ assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{next_month.year}/#{prev_month.month}"}, :content => prev_month_name
+ assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{prev_month.year}/#{next_month.month}"}, :content => next_month_name
end
end
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 2105a77..137be0e 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -320,7 +320,7 @@ class SearchControllerTest < ActionController::TestCase
ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month)
get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year
- assert_equal [ev1], assigns(:events_of_the_day)
+ assert_equal [ev1], assigns(:events)
end
should 'return events of the day with category' do
@@ -332,7 +332,7 @@ class SearchControllerTest < ActionController::TestCase
get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/')
- assert_equal [ev1], assigns(:events_of_the_day)
+ assert_equal [ev1], assigns(:events)
end
should 'return events of today when no date specified' do
@@ -342,7 +342,7 @@ class SearchControllerTest < ActionController::TestCase
get :events
- assert_equal [ev1], assigns(:events_of_the_day)
+ assert_equal [ev1], assigns(:events)
end
should 'show events for current month by default' do
diff --git a/test/unit/dates_helper_test.rb b/test/unit/dates_helper_test.rb
index d3a32a8..238ae0d 100644
--- a/test/unit/dates_helper_test.rb
+++ b/test/unit/dates_helper_test.rb
@@ -108,40 +108,7 @@ class DatesHelperTest < ActiveSupport::TestCase
assert_equal 'September 2009', show_month(2009, 10, :previous => true)
end
- should 'provide link to previous month' do
- expects(:link_to).with('January 2008', { :year => 2008, :month => 1})
- link_to_previous_month('2008', '2')
- end
-
- should 'support last year in link to previous month' do
- expects(:link_to).with('December 2007', { :year => 2007, :month => 12})
- link_to_previous_month('2008', '1')
- end
-
- should 'provide link to next month' do
- expects(:link_to).with('March 2008', { :year => 2008, :month => 3})
- link_to_next_month('2008', '2')
- end
-
- should 'support next year in link to next month' do
- expects(:link_to).with('January 2009', { :year => 2009, :month => 1})
- link_to_next_month('2008', '12')
- end
-
- should 'get current date when year and month are not informed for next month' do
- Date.stubs(:today).returns(Date.new(2008,1,1))
- expects(:link_to).with('February 2008', { :year => 2008, :month => 2})
- link_to_next_month(nil, nil)
- end
-
- should 'get current date when year and month are not informed for previous month' do
- Date.stubs(:today).returns(Date.new(2008,1,1))
- expects(:link_to).with('December 2007', { :year => 2007, :month => 12})
- link_to_previous_month(nil, nil)
- end
-
should 'provide an intertionalized date selector pass month names' do
-
expects(:gettext).with('January').returns('January')
expects(:gettext).with('February').returns('February')
expects(:gettext).with('March').returns('March')
@@ -154,7 +121,6 @@ class DatesHelperTest < ActiveSupport::TestCase
expects(:gettext).with('October').returns('October')
expects(:gettext).with('November').returns('November')
expects(:gettext).with('December').returns('December')
-
expects(:language).returns('en')
expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']}).returns("KKKKKKKK")
diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb
index 95aab5e..d6e73d8 100644
--- a/test/unit/event_test.rb
+++ b/test/unit/event_test.rb
@@ -100,13 +100,13 @@ class EventTest < ActiveSupport::TestCase
should 'provide range of dates for event with both dates filled' do
e = Event.new(:start_date => Date.new(2008, 1, 1), :end_date => Date.new(2008, 1, 5))
-
+
assert_equal (Date.new(2008,1,1)..Date.new(2008,1,5)), e.date_range
end
should 'provide range of dates for event with only start date' do
e = Event.new(:start_date => Date.new(2008, 1, 1))
-
+
assert_equal (Date.new(2008,1,1)..Date.new(2008,1,1)), e.date_range
end
@@ -116,7 +116,6 @@ class EventTest < ActiveSupport::TestCase
assert_tag_in_string e.to_html, :content => Regexp.new("January 1, 2008")
assert_tag_in_string e.to_html, :content => 'my somewhat short description'
assert_tag_in_string e.to_html, :tag => 'a', :attributes => { :href => 'http://www.myevent.org' }, :content => 'http://www.myevent.org'
-
end
should 'not crash when body is blank' do
@@ -187,6 +186,47 @@ class EventTest < ActiveSupport::TestCase
assert_equal [today_event], profile.events.by_day(today)
end
+ should 'list events by month' do
+ profile = fast_create(Profile)
+
+ today = Date.new(2013, 10, 6)
+
+ last_month_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.month)
+
+ current_month_event_1 = Event.new(:name => 'Maria Birthday', :start_date => today)
+ current_month_event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day)
+
+ next_month_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.month)
+
+ profile.events << [last_month_event, current_month_event_1, current_month_event_2, next_month_event]
+
+ month_events = profile.events.by_month(today)
+
+ assert month_events.include?(current_month_event_1)
+ assert month_events.include?(current_month_event_2)
+
+ assert !month_events.include?(last_month_event)
+ assert !month_events.include?(next_month_event)
+ end
+
+ should 'event by month ordered by start date'do
+ profile = fast_create(Profile)
+
+ today = Date.new(2013, 10, 6)
+
+ event_1 = Event.new(:name => 'Maria Birthday', :start_date => today + 1.day)
+ event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day)
+ event_3 = Event.new(:name => 'Mane Birthday', :start_date => today)
+
+ profile.events << [event_1, event_2, event_3]
+
+ events = profile.events.by_month(today)
+
+ assert_equal events[0], event_2
+ assert_equal events[1], event_3
+ assert_equal events[2], event_1
+ end
+
should 'list events in a range' do
profile = fast_create(Profile)
diff --git a/test/unit/events_helper_test.rb b/test/unit/events_helper_test.rb
index e396c36..a979f41 100644
--- a/test/unit/events_helper_test.rb
+++ b/test/unit/events_helper_test.rb
@@ -5,12 +5,33 @@ class EventsHelperTest < ActiveSupport::TestCase
include EventsHelper
should 'list events' do
- stubs(:user)
- expects(:show_date).returns('')
- expects(:_).with('Events for %s').returns('')
- event1 = mock; event1.expects(:display_to?).with(anything).returns(true); event1.expects(:name).returns('Event 1'); event1.expects(:url).returns({})
- event2 = mock; event2.expects(:display_to?).with(anything).returns(true); event2.expects(:name).returns('Event 2'); event2.expects(:url).returns({})
- result = list_events('', [event1, event2])
+ user = create_user('userwithevents').person
+ stubs(:user).returns(user)
+
+ expects(:show_date_month).returns('')
+ expects(:_).with('Events for %s').returns('').once
+ expects(:_).with(' to ').returns('').twice
+ expects(:_).with('Place: ').returns('').twice
+ expects(:_).with('No events for this month').returns('').never
+
+ event1 = mock;
+ event1.expects(:display_to?).with(anything).returns(true).once;
+ event1.expects(:start_date).returns(Date.today).once
+ event1.expects(:end_date).returns(Date.today + 1.day).twice
+ event1.expects(:name).returns('Event 1').once
+ event1.expects(:url).returns({}).once
+ event1.expects(:address).returns('The Shire').times(3)
+
+ event2 = mock;
+ event2.expects(:display_to?).with(anything).returns(true).once
+ event2.expects(:start_date).returns(Date.today).once
+ event2.expects(:end_date).returns(Date.today + 1.day).twice
+ event2.expects(:name).returns('Event 2').once
+ event2.expects(:url).returns({}).once
+ event2.expects(:address).returns('Valfenda').times(3)
+
+ result = list_events(Date.today, [event1, event2])
+
assert_match /Event 1/, result
assert_match /Event 2/, result
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 5da1312..24b51fb 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1445,6 +1445,19 @@ class ProfileTest < ActiveSupport::TestCase
assert_equal [today_event], profile.events.by_day(today)
end
+ should 'list events by month' do
+ profile = fast_create(Profile)
+
+ today = Date.today
+ yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day)
+ today_event = Event.new(:name => 'Ze Birthday', :start_date => today)
+ tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day)
+
+ profile.events << [yesterday_event, today_event, tomorrow_event]
+
+ assert_equal [yesterday_event, today_event, tomorrow_event], profile.events.by_month(today)
+ end
+
should 'list events in a range' do
profile = fast_create(Profile)
@@ -1474,13 +1487,13 @@ class ProfileTest < ActiveSupport::TestCase
assert_not_includes profile.events.by_day(today), event_out_of_range
end
- should 'sort events by name' do
+ should 'sort events by date' do
profile = fast_create(Profile)
event1 = Event.new(:name => 'Noosfero Hackaton', :start_date => Date.today)
- event2 = Event.new(:name => 'Debian Day', :start_date => Date.today)
- event3 = Event.new(:name => 'Fisl 10', :start_date => Date.today)
+ event2 = Event.new(:name => 'Debian Day', :start_date => Date.today - 1)
+ event3 = Event.new(:name => 'Fisl 10', :start_date => Date.today + 1)
profile.events << [event1, event2, event3]
- assert_equal [event2, event3, event1], profile.events
+ assert_equal [event2, event1, event3], profile.events
end
should 'be available if identifier doesnt exist on environment' do
--
libgit2 0.21.2