Skip to content

Commit

Permalink
Store comment for commitment and display the current user's comment. …
Browse files Browse the repository at this point in the history
…[#69]
  • Loading branch information
marnen committed Mar 8, 2012
1 parent 35316b6 commit e5f9f44
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/controllers/events_controller.rb
Expand Up @@ -102,7 +102,7 @@ def change_status
status_map = {'yes' => true, 'no' => false, 'maybe' => nil}
if !id.nil? then
event = Event.find_by_id(id)
event.change_status!(current_user, status_map[params[:status].to_s])
event.change_status! current_user, status_map[params[:status].to_s], params[:comment]
end
if request.xhr?
render :partial => 'event', :locals => {:event => event}
Expand Down Expand Up @@ -153,6 +153,7 @@ def current_objects
date_query = 'date >= :from_date'
end

# TODO: use "#{}" for query string.
@current_objects || Event.where(['calendar_id IN (:calendars) AND ' + date_query, {:calendars => calendars, :from_date => from_date, :to_date => to_date}]).order("#{order} #{direction}")
end

Expand Down
1 change: 1 addition & 0 deletions app/models/event.rb
Expand Up @@ -47,6 +47,7 @@ def find_committed(status)
end
scope = {:yes => :attending, :no => :not_attending}[status]
c = commitments.send(scope)
# TODO: move comparator into the User class, or do the sort on the DB side.
c.collect{|e| e.user }.sort{|x, y| (x.lastname || x.email) <=> (y.lastname || y.email)}
end

Expand Down
2 changes: 2 additions & 0 deletions app/views/events/_attendance.html.haml
Expand Up @@ -2,8 +2,10 @@
- @status_strings ||= { :yes => _('attending'), :no => _('not attending'), :maybe => _('uncommitted') }
- status = attendance_status(event, User.current_user)
%td{:class => status}
-# TODO: why not make this form_for commitment ?
= form_for event, :as => :commitment, :url => {:action => :change_status, :id => event.id}, :html => {:class => :attendance} do |f|
%p!= _("You are currently %{status}.") % {:status => content_tag(:span, h(@status_strings[status]), :class => status)}
= select_tag(:status, options_for_select(@status_strings.invert, status), :class => :commit, :id => nil)
%span.progress &nbsp;
= text_area_tag :comment, attendance_comment(event, User.current_user)
= submit_tag(h(_("Change status")))
4 changes: 3 additions & 1 deletion app/views/events/_event.html.haml
Expand Up @@ -31,9 +31,11 @@
%div.description
:markdown
#{h event.description}
%div.comments
%span.user== #{current_user}:
= attendance_comment event, current_user
= render :partial => 'attendance', :locals => {:event => event}
- yes = event.find_committed(:yes)
- no = event.find_committed(:no)
%td= render :partial => 'names', :object => yes
%td= render :partial => 'names', :object => no

18 changes: 18 additions & 0 deletions features/commitments/add_comment_to_commitment.feature
@@ -0,0 +1,18 @@
Feature: Add comment to commitment
As a user
I can add comments to events
So I can qualify my commitment status

Scenario Outline: Add comment to commitment
Given a user named "<name>" exists with email "<email>"
And I am logged in as "<email>"
And I am subscribed to "Calendar 1"
And someone else has an event called "Event" in "Calendar 1"
And I am on the event list
When I fill in "comment" with "<comment>"
And I press "Change status"
Then I should see "<name>: <comment>"

Examples:
| email | name | comment |
| john@smith.com | John Smith | This is my comment text. |
28 changes: 22 additions & 6 deletions features/step_definitions/user_steps.rb
@@ -1,12 +1,18 @@
# coding: UTF-8

Given /^a user named "([^"]*)" exists with email "([^"]*)"$/ do |name, email|
first, last = name.split ' ', 2
Factory :user, firstname: first, lastname: last, email: email
end

Given /^I am logged in as "([^"]*)"$/ do |email|
user = User.find_by_email email
login_as user
end

Given /^I am logged in$/ do
user = FactoryGirl.create :user, :password => 'passw0rd'
visit login_path
fill_in('user_session[email]', :with => user.email)
fill_in('user_session[password]', :with => 'passw0rd')
click_button 'Log in'
UserSession.find.record.should == user
login_as user
end

Given /^I am not logged in$/ do
Expand All @@ -27,4 +33,14 @@
else
user.should_not be_nil
end
end
end

private

def login_as(user)
visit login_path
fill_in('user_session[email]', :with => user.email)
fill_in('user_session[password]', :with => 'passw0rd')
click_button 'Log in'
UserSession.find.record.should == user
end
35 changes: 20 additions & 15 deletions spec/factories.rb
Expand Up @@ -34,65 +34,70 @@
date { Date.civil(rand(10) + 2100, rand(12) + 1, rand(28) + 1) } # way in the future so it shows up on the event list
calendar
association :created_by, :factory => :user

factory :deleted_event do
deleted { true }
end
end

factory :state, :class => Acts::Addressed::State do
country
name { Faker::Name.last_name } # generic_name
code { LETTERS.sample + LETTERS.sample }
end

factory :country, :class => Acts::Addressed::Country do
name { Faker::Name.last_name } # generic_name
code { LETTERS.sample + LETTERS.sample }
end

factory :calendar do
name {Faker::Name.name + "'s calendar"}
end

factory :user do
firstname { Faker::Name.first_name }
lastname { Faker::Name.last_name }
email { Faker::Internet.email }
password { (1..(rand(15) + 4)).map{(32..127).to_a.sample.chr}.join }
password {'passw0rd'}
password_confirmation { password }
street { Faker::Address.street_address }
street2 { Faker::Address.secondary_address }
city {Faker::Address.city}
association :state_raw, :factory => :state
association :state_raw, :factory => :state
zip { Faker::Address.zip_code }
active {true}

factory :inactive_user do
active {false}
end

factory :user_with_random_password do
password { (1..(rand(15) + 4)).map{(32..127).to_a.sample.chr}.join }
end
end

factory :commitment do
event
user
event
user
status {true}
comment { Faker::Lorem.sentence }
end

factory :permission do
user
role
calendar
show_in_report {true}

factory :admin_permission do
association :role, :factory => :admin_role
end
end

factory :role do
name {'user'}

factory :admin_role do
name {'admin'}
end
Expand Down

0 comments on commit e5f9f44

Please sign in to comment.