Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.

Commit

Permalink
Added working controller tests for events controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bnisbett committed Sep 23, 2010
1 parent 2a035b3 commit 5a6453d
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 91 deletions.
11 changes: 9 additions & 2 deletions fullcalendar_rails3/Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.rc'
gem 'rails', '3.0.0'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
#gem 'authlogic', ">=2.1.6"
gem 'meta_where'

group :development do
gem 'rails3-generators'
gem 'thin'
end

group :test, :development do
gem 'rspec-rails', ">=2.0.0.beta.13"
gem 'rspec-rails', ">=2.0.0.beta.20"
end

group :test do
Expand Down
128 changes: 69 additions & 59 deletions fullcalendar_rails3/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/odorcicd/authlogic.git
revision: a087ad0
revision: a087ad0cba3c165ba22fcf176c28b6f7517931e8
branch: rails3
specs:
authlogic (2.1.3)
Expand All @@ -10,37 +10,36 @@ GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.0.rc)
actionpack (= 3.0.0.rc)
actionmailer (3.0.0)
actionpack (= 3.0.0)
mail (~> 2.2.5)
actionpack (3.0.0.rc)
activemodel (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
actionpack (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4.1)
rack (~> 1.2.1)
rack-mount (~> 0.6.9)
rack-mount (~> 0.6.12)
rack-test (~> 0.5.4)
tzinfo (~> 0.3.22)
activemodel (3.0.0.rc)
activesupport (= 3.0.0.rc)
tzinfo (~> 0.3.23)
activemodel (3.0.0)
activesupport (= 3.0.0)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.0.rc)
activemodel (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
arel (~> 0.4.0)
tzinfo (~> 0.3.22)
activeresource (3.0.0.rc)
activemodel (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
activesupport (3.0.0.rc)
arel (0.4.0)
activesupport (>= 3.0.0.beta)
activerecord (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
arel (~> 1.0.0)
tzinfo (~> 0.3.23)
activeresource (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
arel (1.0.1)
activesupport (~> 3.0.0)
autotest (4.3.2)
autotest-fsevent (0.2.2)
autotest (>= 4.2.4)
autotest-fsevent (0.2.3)
sys-uname
autotest-rails-pure (4.1.0)
builder (2.1.2)
Expand All @@ -59,11 +58,13 @@ GEM
term-ansicolor (~> 1.0.4)
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
culerity (0.2.10)
culerity (0.2.12)
daemons (1.1.0)
database_cleaner (0.5.2)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
eventmachine (0.12.10)
factory_girl (1.3.2)
factory_girl_rails (1.0)
factory_girl (~> 1.3)
Expand All @@ -74,66 +75,72 @@ GEM
trollop (~> 1.16.2)
i18n (0.4.1)
json_pure (1.4.6)
mail (2.2.5)
mail (2.2.6.1)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
meta_where (0.9.3)
activerecord (~> 3.0.0)
activesupport (~> 3.0.0)
arel (~> 1.0.1)
mime-types (1.16)
nokogiri (1.4.3.1)
pickle (0.3.5)
pickle (0.4.2)
cucumber (>= 0.8)
rake
rspec (>= 1.3)
yard
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.9)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-test (0.5.4)
rack (>= 1.0)
rails (3.0.0.rc)
actionmailer (= 3.0.0.rc)
actionpack (= 3.0.0.rc)
activerecord (= 3.0.0.rc)
activeresource (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
bundler (>= 1.0.0.rc.1)
railties (= 3.0.0.rc)
railties (3.0.0.rc)
actionpack (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
rake (>= 0.8.3)
rails (3.0.0)
actionmailer (= 3.0.0)
actionpack (= 3.0.0)
activerecord (= 3.0.0)
activeresource (= 3.0.0)
activesupport (= 3.0.0)
bundler (~> 1.0.0)
railties (= 3.0.0)
rails3-generators (0.13.0)
railties (3.0.0)
actionpack (= 3.0.0)
activesupport (= 3.0.0)
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
rspec (2.0.0.beta.19)
rspec-core (= 2.0.0.beta.19)
rspec-expectations (= 2.0.0.beta.19)
rspec-mocks (= 2.0.0.beta.19)
rspec-core (2.0.0.beta.19)
rspec-expectations (2.0.0.beta.19)
rspec (2.0.0.beta.22)
rspec-core (= 2.0.0.beta.22)
rspec-expectations (= 2.0.0.beta.22)
rspec-mocks (= 2.0.0.beta.22)
rspec-core (2.0.0.beta.22)
rspec-expectations (2.0.0.beta.22)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.19)
rspec-rails (2.0.0.beta.19)
rspec (= 2.0.0.beta.19)
webrat (>= 0.7.2.beta.1)
rspec-mocks (2.0.0.beta.22)
rspec-core (= 2.0.0.beta.22)
rspec-expectations (= 2.0.0.beta.22)
rspec-rails (2.0.0.beta.22)
rspec (= 2.0.0.beta.22)
rubyzip (0.9.4)
selenium-webdriver (0.0.27)
selenium-webdriver (0.0.28)
ffi (>= 0.6.1)
json_pure
rubyzip
sqlite3-ruby (1.3.1)
sys-uname (0.8.4)
term-ansicolor (1.0.5)
thor (0.14.0)
thin (1.2.7)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.14.1)
treetop (1.4.8)
polyglot (>= 0.3.1)
trollop (1.16.2)
tzinfo (0.3.22)
webrat (0.7.2.beta.1)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
yard (0.5.8)
tzinfo (0.3.23)
yard (0.6.1)

PLATFORMS
ruby
Expand All @@ -148,7 +155,10 @@ DEPENDENCIES
cucumber-rails
database_cleaner
factory_girl_rails
meta_where
pickle
rails (= 3.0.0.rc)
rspec-rails (>= 2.0.0.beta.13)
rails (= 3.0.0)
rails3-generators
rspec-rails (>= 2.0.0.beta.20)
sqlite3-ruby
thin
4 changes: 2 additions & 2 deletions fullcalendar_rails3/app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class EventsController < ApplicationController
before_filter :require_user, :except => [:index]
before_filter :require_user, :except => [:index,:list]

def list
@events = Event.all
@events = Event.soon_on_call
end
# GET /events
# GET /events.xml
Expand Down
10 changes: 5 additions & 5 deletions fullcalendar_rails3/app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class Event < ActiveRecord::Base
validate :endDate_cannot_be_in_the_past

def endDate_cannot_be_in_the_past
errors.add(:endDate,"can't be in the past") if (!(startDate.blank? || endDate.blank?) && (self.startDate > self.endDate))
end
=begin
errors.add(:endDate,"can't be in the past") if (!(startDate.blank? || endDate.blank?) && (self.startDate > self.endDate))
end

def self.soon_on_call
where({:startDate => Date.yesterday..Date.today.end_of_week} | {:endDate =>Date.yesterday..Date.today.end_of_week})
where({:startDate => Date.yesterday..Date.today.end_of_week} | {:endDate =>Date.yesterday..Date.today.end_of_week}).order("startDate")
end
=end

end
7 changes: 3 additions & 4 deletions fullcalendar_rails3/app/views/events/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
<% @events.each do |event| %>
<tr>

<th><%= event.startDate.strftime("%a, %d %b %Y") %></th>

<td><%=h event.startTime.strftime("%I:%M%p") %> - <%= event.endTime.strftime("%I:%M%p") %></td>
<td><%=h event.supporter.name %></td>
<td><%= event.startDate.strftime("%a, %d %b %Y") %> at <%=h event.startTime.strftime("%I:%M%p") %></td>
<td><%= event.endDate.strftime("%a, %d %b %Y") %> at <%= event.endTime.strftime("%I:%M%p") %></td>
<th><%=h event.supporter.name %></th>
</tr>
<% end %>
</table>
Expand Down
14 changes: 1 addition & 13 deletions fullcalendar_rails3/app/views/events/new.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,8 @@ $('#create_event_dialog').dialog({
$.validator.addMethod("endDateGreater", function(value,element,params){
var startDate = new Date($('#event_startDate').val());
var endDate = new Date($('#event_endDate').val());
return this.optional(element) || endDate > startDate;
return this.optional(element) || endDate >= startDate;
}, jQuery.format("End Date Must Be Greater Than Start Date"));

/*
$.validator.addMethod("endDateGreater", function(value, element, params) {
if (!/Invalid|NaN/.test(new Date(value))) {
return new Date(value) > new Date($(params[1]).val());
}
return isNaN(value) && isNaN($(params[1]).val()) || (parseFloat(value) > parseFloat($(params[1]).val() ) );
},'Must be greater than {1}.');
*/


$("#new_event").validate({
rules: {
Expand Down
56 changes: 52 additions & 4 deletions fullcalendar_rails3/spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,63 @@
end
end

describe "Authenticated examples" do
before(:each) do
activate_authlogic
UserSession.create Factory.build(:valid_user)
end

describe "handling GET /events" do
before(:each) do
@event = mock(:event)
Event.should_receive(:find).and_return(@event)
#Event.stub!(:find).and_return([@event])
end

it "should be successful" do
get :edit, :id => "1"
response.should be_success
end

it "should render edit template" do
get :edit, :id => '1'
response.should render_template('edit')
end

it "should render show template" do
get :show, :id => '1'
response.should render_template('show')
end
end
end
end





=begin
describe 'GET edit' do
before { login }
it 'should render edit js view' do
events = [mock(:event), mock(:event)]
Event.should_receive(:all).and_return(events)
get :edit, :format =>'js'
response.should render_template('events/edit.js.erb')
end
end
describe "edit format js" do
it "should respond to javascript" do
event = mock(:event)
Event.should_receive(:find).and_return(event)
get 'edit'
#@event = mock(:event)
#Event.should_receive(:find).and_return(@event)
get :edit, :format => 'js'
#assigns[:event].should == event
#response.should be_success
#get :edit, :format => 'js'
#response.should render_template('events/edit')
end
end
Expand Down Expand Up @@ -61,5 +109,5 @@
#response.should render_template('events/destroy.js.erb')
end
end
=end

end
9 changes: 9 additions & 0 deletions fullcalendar_rails3/spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
u.login"Test user"
u.password "test"
u.password_confirmation "test"
end

Factory.define :valid_user, :class => User do |u|
u.login "benny"
u.password 'benrocks'
u.password_confirmation 'benrocks'
u.password_salt 'CVVMAm9XxdwXpURdQG1N'
u.crypted_password 'fb2454b8d22edacc6e88a55972ed5a...'
u.persistence_token '6cde0674657a8a313ce952df979de2830309aa4c11ca6...'
end
4 changes: 2 additions & 2 deletions fullcalendar_rails3/spec/models/supporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
supporter.should have(2).error_on(:email) # We expect 2 errors - email empty and in wrong format because it is empty
end
end
begin
#begin
describe :supporter_without_isIT do
it "should validate presence of IT/Developer Status" do
supporter = Factory.build(:supporter, :isIT => nil)
supporter.should be_invalid
supporter.should have(1).error_on(:isIT)
end
end
end
#end
describe :supporter_with_incorrect_phone_format do
it "should validate format of phone number" do
supporter = Factory.build(:supporter, :phone => "123djeursa33333eee")
Expand Down
Loading

0 comments on commit 5a6453d

Please sign in to comment.