├── lib └── eventify.rb ├── init.rb ├── install.rb ├── uninstall.rb ├── spec ├── rcov.opts ├── spec.opts ├── integration │ └── events_spec.rb ├── helpers │ └── events_helper_spec.rb ├── views │ └── events │ │ ├── show.html.erb_spec.rb │ │ ├── new.html.erb_spec.rb │ │ ├── edit.html.erb_spec.rb │ │ ├── index.html.erb_spec.rb │ │ └── partials.html.erb_spec.rb ├── fixtures │ └── events.yml ├── spec_helper.rb ├── models │ └── event_spec.rb ├── routing │ └── events_routing_spec.rb └── controllers │ └── events_controller_spec.rb ├── test ├── test_helper.rb └── eventify_test.rb ├── config ├── initializers │ └── date_formats.rb └── routes.rb ├── app ├── views │ ├── events │ │ ├── _quickie_new.html.erb │ │ ├── _quickie_form.html.erb │ │ ├── _quickie_edit.html.erb │ │ ├── show.html.erb │ │ ├── index.html.erb │ │ ├── _list_item.html.erb │ │ ├── new.html.erb │ │ └── edit.html.erb │ └── layouts │ │ └── events.html.erb ├── models │ └── event.rb ├── helpers │ └── events_helper.rb └── controllers │ └── events_controller.rb ├── db └── migrate │ └── 20090908093001_create_events.rb ├── tasks └── eventify_tasks.rake ├── Rakefile ├── README ├── MIT-LICENSE └── public └── stylesheets └── scaffold.css /lib/eventify.rb: -------------------------------------------------------------------------------- 1 | # Eventify 2 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | # Include hook code here 2 | -------------------------------------------------------------------------------- /install.rb: -------------------------------------------------------------------------------- 1 | # Install hook code here 2 | -------------------------------------------------------------------------------- /uninstall.rb: -------------------------------------------------------------------------------- 1 | # Uninstall hook code here 2 | -------------------------------------------------------------------------------- /spec/rcov.opts: -------------------------------------------------------------------------------- 1 | --exclude "spec/*,gems/*" 2 | --rails -------------------------------------------------------------------------------- /spec/spec.opts: -------------------------------------------------------------------------------- 1 | --colour 2 | --format progress 3 | --loadby mtime 4 | --reverse 5 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'active_support' 3 | require 'active_support/test_case' -------------------------------------------------------------------------------- /spec/integration/events_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') 2 | 3 | describe "Events" do 4 | end 5 | -------------------------------------------------------------------------------- /test/eventify_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class EventifyTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /config/initializers/date_formats.rb: -------------------------------------------------------------------------------- 1 | ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:local => '%d/%m/%Y') 2 | 3 | ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:local => '%d/%m/%Y %H:%M') -------------------------------------------------------------------------------- /app/views/events/_quickie_new.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <% remote_form_for(:event, :url => create_quickie_events_path, :update => {:failure => "quickie_form"}) do |f| %> 3 | <%= render :partial => "/events/quickie_form", :locals => {:f => f, :act => "new"} %> 4 | <% end %> -------------------------------------------------------------------------------- /app/views/events/_quickie_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= f.error_messages %> 2 | 3 | <%= f.select :priority, options_for_select(Event::PRIORITIES) %> 4 | <%= f.text_field :title %> 5 | <%= f.date_select :due %> 6 | 7 | <% if act == "new" %> 8 | <%= f.submit 'Create' %> 9 | <% elsif act == "edit" %> 10 | <%= f.submit 'Update' %> 11 | <% end %> 12 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | ActionController::Routing::Routes.draw do |map| 2 | map.resources :events, :member => {:done => :post}, :collection => {:create_quickie => :post} 3 | map.period_events 'events/period/:period', :controller => 'events', :action => 'index' 4 | 5 | map.connect ':controller/:action/:id' 6 | map.connect ':controller/:action/:id.:format' 7 | end 8 | -------------------------------------------------------------------------------- /app/views/events/_quickie_edit.html.erb: -------------------------------------------------------------------------------- 1 | <% remote_form_for(:event, :url => event_path(@event, :format => :js), :html => {:method => :put}, :update => {:failure => "event_#{@event.id}"}) do |f| %> 2 | <%= render :partial => "/events/quickie_form", :locals => {:f => f, :act => "edit"} %> 3 | <%= link_to_remote "Cancel", {:url => event_path(@event), :method => :get} %> 4 | <% end %> -------------------------------------------------------------------------------- /spec/helpers/events_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') 2 | 3 | describe EventsHelper do 4 | 5 | #Delete this example and add some real ones or delete this file 6 | it "is included in the helper object" do 7 | included_modules = (class << helper; self; end).send :included_modules 8 | included_modules.should include(EventsHelper) 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20090908093001_create_events.rb: -------------------------------------------------------------------------------- 1 | class CreateEvents < ActiveRecord::Migration 2 | def self.up 3 | create_table :events do |t| 4 | t.integer :user_id 5 | t.string :title 6 | t.integer :priority 7 | t.datetime :due 8 | t.boolean :done 9 | t.datetime :created_at 10 | t.datetime :updated_at 11 | 12 | t.timestamps 13 | end 14 | end 15 | 16 | def self.down 17 | drop_table :events 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /tasks/eventify_tasks.rake: -------------------------------------------------------------------------------- 1 | namespace :eventify do 2 | desc "Sync extra files from eventify plugin." 3 | task :sync do 4 | system "rsync -ruv vendor/plugins/eventify/db/migrate db" 5 | system "rsync -ruv vendor/plugins/eventify/app ." 6 | system "rsync -ruv vendor/plugins/eventify/config ." 7 | system "rsync -ruv vendor/plugins/eventify/public/stylesheets public" 8 | system "rsync -ruv vendor/plugins/eventify/spec ." 9 | end 10 | end -------------------------------------------------------------------------------- /app/models/event.rb: -------------------------------------------------------------------------------- 1 | class Event < ActiveRecord::Base 2 | 3 | PRIORITIES = [["high", 1], ["medium", 2], ["low", 3]] 4 | 5 | validates_presence_of :title 6 | validates_inclusion_of :priority, :in => [1, 2, 3] 7 | 8 | attr_accessible :title, :priority, :due 9 | 10 | def mark_as_done 11 | self.update_attribute(:done, true) 12 | end 13 | 14 | def unmark_as_done 15 | self.update_attribute(:done, false) 16 | end 17 | 18 | private 19 | def self.fetch_for_period(left, right) 20 | self.find(:all, :conditions => ["due >= ? AND due < ?", left, right], :order => "priority, due") 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/views/layouts/events.html.erb: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | Events: <%= controller.action_name %> 8 | <%= stylesheet_link_tag 'scaffold' %> 9 | <%= javascript_include_tag :defaults %> 10 | 11 | 12 |
<%= flash[:notice] %>
13 | 14 | <%= yield %> 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/views/events/show.html.erb: -------------------------------------------------------------------------------- 1 |

2 | User: 3 | <%=h @event.user_id %> 4 |

5 | 6 |

7 | Title: 8 | <%=h @event.title %> 9 |

10 | 11 |

12 | Priority: 13 | <%=h @event.priority %> 14 |

15 | 16 |

17 | Due: 18 | <%=h @event.due %> 19 |

20 | 21 |

22 | Done: 23 | <%=h @event.done %> 24 |

25 | 26 |

27 | Created at: 28 | <%=h @event.created_at %> 29 |

30 | 31 |

32 | Updated at: 33 | <%=h @event.updated_at %> 34 |

35 | 36 | 37 | <%= link_to 'Edit', edit_event_path(@event) %> | 38 | <%= link_to 'Back', events_path %> -------------------------------------------------------------------------------- /spec/views/events/show.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') 2 | 3 | describe "/events/show.html.erb" do 4 | include EventsHelper 5 | before(:each) do 6 | assigns[:event] = @event = stub_model(Event, 7 | :user_id => 1, 8 | :title => "value for title", 9 | :priority => 1, 10 | :done => false 11 | ) 12 | end 13 | 14 | it "renders attributes in

" do 15 | render 16 | response.should have_text(/1/) 17 | response.should have_text(/value\ for\ title/) 18 | response.should have_text(/1/) 19 | response.should have_text(/false/) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'rake/testtask' 3 | require 'rake/rdoctask' 4 | 5 | desc 'Default: run unit tests.' 6 | task :default => :test 7 | 8 | desc 'Test the eventify plugin.' 9 | Rake::TestTask.new(:test) do |t| 10 | t.libs << 'lib' 11 | t.libs << 'test' 12 | t.pattern = 'test/**/*_test.rb' 13 | t.verbose = true 14 | end 15 | 16 | desc 'Generate documentation for the eventify plugin.' 17 | Rake::RDocTask.new(:rdoc) do |rdoc| 18 | rdoc.rdoc_dir = 'rdoc' 19 | rdoc.title = 'Eventify' 20 | rdoc.options << '--line-numbers' << '--inline-source' 21 | rdoc.rdoc_files.include('README') 22 | rdoc.rdoc_files.include('lib/**/*.rb') 23 | end 24 | -------------------------------------------------------------------------------- /app/views/events/index.html.erb: -------------------------------------------------------------------------------- 1 | 2 |

Listing events

3 | 4 |

New event

5 | 6 |
7 | <%= render :partial => "/events/quickie_new" %> 8 |
9 | 10 | 17 | 18 |
19 | <%= render :partial => "/events/list_item", :collection => @events %> 20 |
21 | 22 |
23 | 24 | <%#= link_to 'New event', new_event_path %> -------------------------------------------------------------------------------- /app/views/events/_list_item.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <%= check_box_to_remote "cb_#{list_item.id}", value = "1", checked = (list_item.done), {:url => done_event_path(list_item)} %> 3 | 4 | <% if list_item.done %> 5 | 6 | <%=h (list_item.due) ? list_item.due.to_s(:local) : "-" %> 7 | <%= priority_title(list_item.priority) %> 8 | <%= h(list_item.title) %> 9 | 10 | <% else %> 11 | <%=h (list_item.due) ? list_item.due.to_s(:local) : "-" %> 12 | <%= priority_color(list_item.priority) %> 13 | <%= link_to_remote(h(list_item.title), {:url => edit_event_path(list_item, :format => :js), :method => :get}, :title => "Edit item") %> 14 | <%= link_to('[X]', list_item, :confirm => 'Are you sure?', :method => :delete, :title => "Delete item") %> 15 | <% end %> 16 |
17 | -------------------------------------------------------------------------------- /spec/views/events/new.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') 2 | 3 | describe "/events/new.html.erb" do 4 | include EventsHelper 5 | 6 | before(:each) do 7 | assigns[:event] = stub_model(Event, 8 | :new_record? => true, 9 | :user_id => 1, 10 | :title => "value for title", 11 | :priority => 1, 12 | :done => false 13 | ) 14 | end 15 | 16 | it "renders new event form" do 17 | render 18 | 19 | response.should have_tag("form[action=?][method=post]", events_path) do 20 | with_tag("input#event_user_id[name=?]", "event[user_id]") 21 | with_tag("input#event_title[name=?]", "event[title]") 22 | with_tag("input#event_priority[name=?]", "event[priority]") 23 | with_tag("input#event_done[name=?]", "event[done]") 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /spec/views/events/edit.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') 2 | 3 | describe "/events/edit.html.erb" do 4 | include EventsHelper 5 | 6 | before(:each) do 7 | assigns[:event] = @event = stub_model(Event, 8 | :new_record? => false, 9 | :user_id => 1, 10 | :title => "value for title", 11 | :priority => 1, 12 | :done => false 13 | ) 14 | end 15 | 16 | it "renders the edit event form" do 17 | render 18 | 19 | response.should have_tag("form[action=#{event_path(@event)}][method=post]") do 20 | with_tag('input#event_user_id[name=?]', "event[user_id]") 21 | with_tag('input#event_title[name=?]', "event[title]") 22 | with_tag('input#event_priority[name=?]', "event[priority]") 23 | with_tag('input#event_done[name=?]', "event[done]") 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /spec/fixtures/events.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | user_id: 1 5 | title: MyString 6 | priority: 2 7 | due: <%= Date.today %> 8 | done: false 9 | created_at: 2009-09-08 12:30:01 10 | updated_at: 2009-09-08 12:30:01 11 | 12 | two: 13 | user_id: 1 14 | title: MyString 15 | priority: 1 16 | due: <%= Date.today + 1 %> 17 | done: false 18 | created_at: <%= 5.hours.ago %> 19 | updated_at: <%= 5.hours.ago %> 20 | 21 | three: 22 | user_id: 1 23 | title: MyString 24 | priority: 3 25 | due: <%= Date.today + 8 %> 26 | done: false 27 | created_at: 2009-09-08 12:30:01 28 | updated_at: 2009-09-08 12:30:01 29 | 30 | four: 31 | user_id: 1 32 | title: MyString 33 | priority: 1 34 | due: <%= Date.today + 100 %> 35 | done: false 36 | created_at: 2009-09-08 12:30:01 37 | updated_at: 2009-09-08 12:30:01 38 | 39 | -------------------------------------------------------------------------------- /app/views/events/new.html.erb: -------------------------------------------------------------------------------- 1 |

New event

2 | 3 | <% form_for(@event) do |f| %> 4 | <%= f.error_messages %> 5 | 6 |

7 | <%= f.label :user_id %>
8 | <%= f.text_field :user_id %> 9 |

10 |

11 | <%= f.label :title %>
12 | <%= f.text_field :title %> 13 |

14 |

15 | <%= f.label :priority %>
16 | <%= f.text_field :priority %> 17 |

18 |

19 | <%= f.label :due %>
20 | <%= f.datetime_select :due %> 21 |

22 |

23 | <%= f.label :done %>
24 | <%= f.check_box :done %> 25 |

26 |

27 | <%= f.label :created_at %>
28 | <%= f.datetime_select :created_at %> 29 |

30 |

31 | <%= f.label :updated_at %>
32 | <%= f.datetime_select :updated_at %> 33 |

34 |

35 | <%= f.submit 'Create' %> 36 |

37 | <% end %> 38 | 39 | <%= link_to 'Back', events_path %> -------------------------------------------------------------------------------- /app/views/events/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing event

2 | 3 | <% form_for(@event) do |f| %> 4 | <%= f.error_messages %> 5 | 6 |

7 | <%= f.label :user_id %>
8 | <%= f.text_field :user_id %> 9 |

10 |

11 | <%= f.label :title %>
12 | <%= f.text_field :title %> 13 |

14 |

15 | <%= f.label :priority %>
16 | <%= f.text_field :priority %> 17 |

18 |

19 | <%= f.label :due %>
20 | <%= f.datetime_select :due %> 21 |

22 |

23 | <%= f.label :done %>
24 | <%= f.check_box :done %> 25 |

26 |

27 | <%= f.label :created_at %>
28 | <%= f.datetime_select :created_at %> 29 |

30 |

31 | <%= f.label :updated_at %>
32 | <%= f.datetime_select :updated_at %> 33 |

34 |

35 | <%= f.submit 'Update' %> 36 |

37 | <% end %> 38 | 39 | <%= link_to 'Show', @event %> | 40 | <%= link_to 'Back', events_path %> -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Eventify 2 | ======== 3 | 4 | Eventify is a primitive events manager. 5 | 6 | 7 | Example 8 | ======= 9 | 10 | - Create new Rails app 11 | 12 | rails myapp 13 | cd myapp 14 | 15 | 16 | - Install RSpec plugins if you do not have rspec and rspec-rails gems installed 17 | 18 | ruby script/plugin install git://github.com/dchelimsky/rspec.git 19 | ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git 20 | ruby script/generate rspec 21 | 22 | 23 | - Install plugin 24 | 25 | script/plugin install git://github.com/bob/eventify.git 26 | rake eventify:sync 27 | rake db:migrate 28 | 29 | 30 | - Comment line in config/environment.rb due time should be local 31 | 32 | # config.time_zone = 'UTC' 33 | 34 | 35 | - Run server 36 | 37 | script/server 38 | 39 | 40 | - In browser 41 | 42 | http://localhost:3000/events 43 | 44 | 45 | - Run tests 46 | 47 | rake spec:rcov 48 | spec spec --format html > doc/specs.html 49 | 50 | 51 | Copyright (c) 2009 Vadim Kalion, released under the MIT license 52 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 [name of plugin creator] 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /app/helpers/events_helper.rb: -------------------------------------------------------------------------------- 1 | module EventsHelper 2 | def priority_color(e) 3 | colors = ["red", "yellow", "green"] 4 | "#{priority_title(e)}" 5 | end 6 | 7 | def priority_title(num) 8 | return num unless [1,2,3].include? num.to_i 9 | Event::PRIORITIES[num-1][0] 10 | end 11 | 12 | def check_box_to_remote(name, value = "1", checked = false, options = {}, html_options = nil) 13 | check_box_to_function(name, value, checked, remote_function(options), html_options || options.delete(:html)) 14 | end 15 | 16 | private 17 | def check_box_to_function(name, value = "1", checked = false, *args, &block) 18 | html_options = args.extract_options!.symbolize_keys 19 | html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(args.extract_options!.stringify_keys) 20 | html_options["checked"] = "checked" if checked 21 | 22 | function = block_given? ? update_page(&block) : args[0] || '' 23 | onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" 24 | href = html_options[:href] || '#' 25 | 26 | tag(:input, html_options.merge(:onclick => onclick)) 27 | # tag :input, html_options 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /public/stylesheets/scaffold.css: -------------------------------------------------------------------------------- 1 | body { background-color: #fff; color: #333; } 2 | 3 | body, p, ol, ul, td { 4 | font-family: verdana, arial, helvetica, sans-serif; 5 | font-size: 13px; 6 | line-height: 18px; 7 | } 8 | 9 | pre { 10 | background-color: #eee; 11 | padding: 10px; 12 | font-size: 11px; 13 | } 14 | 15 | a { color: #000; } 16 | a:visited { color: #666; } 17 | a:hover { color: #fff; background-color:#000; } 18 | 19 | .fieldWithErrors { 20 | padding: 2px; 21 | background-color: red; 22 | display: table; 23 | } 24 | 25 | #errorExplanation { 26 | width: 400px; 27 | border: 2px solid red; 28 | padding: 7px; 29 | padding-bottom: 12px; 30 | margin-bottom: 20px; 31 | background-color: #f0f0f0; 32 | } 33 | 34 | #errorExplanation h2 { 35 | text-align: left; 36 | font-weight: bold; 37 | padding: 5px 5px 5px 15px; 38 | font-size: 12px; 39 | margin: -7px; 40 | background-color: #c00; 41 | color: #fff; 42 | } 43 | 44 | #errorExplanation p { 45 | color: #333; 46 | margin-bottom: 0; 47 | padding: 5px; 48 | } 49 | 50 | #errorExplanation ul li { 51 | font-size: 12px; 52 | list-style: square; 53 | } 54 | 55 | .period_links { 56 | font-size: 18px; 57 | font-weight: bold; 58 | padding: 10px 0 10px 0; 59 | } 60 | 61 | .list_item_title { 62 | font-size: 14px; 63 | font-weight: bold; 64 | } -------------------------------------------------------------------------------- /spec/views/events/index.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') 2 | 3 | describe "/events/index.html.erb" do 4 | include EventsHelper 5 | 6 | before(:each) do 7 | assigns[:events] = [ 8 | stub_model(Event, 9 | :user_id => 1, 10 | :title => "value for title 1", 11 | :priority => 1, 12 | :done => false 13 | ), 14 | stub_model(Event, 15 | :user_id => 1, 16 | :title => "value for title 2", 17 | :priority => 1, 18 | :done => false 19 | ) 20 | ] 21 | end 22 | 23 | it "renders a list of events" do 24 | render 25 | response.should have_tag("div[id='quickie_form']") 26 | response.should have_tag("div[id=?]", "event_#{assigns[:events][0].id}") do 27 | with_tag("input[type=checkbox][name=?][onclick*=Ajax.Request]", "cb_#{assigns[:events][0].id}") 28 | with_tag("font[color=red]", "high") 29 | end 30 | 31 | end 32 | 33 | it "should include quickie form" do 34 | template.should_receive(:render).with(:partial => "/events/quickie_new") 35 | render 36 | end 37 | 38 | it "should show periods links" do 39 | render 40 | response.should have_tag("div.period_links", /^Today/) 41 | response.should have_tag("a[href=?]", period_events_url(:period => "week")) 42 | response.should have_tag("a[href=?]", period_events_url(:period => "month")) 43 | response.should have_tag("a[href=?]", period_events_url(:period => "year")) 44 | end 45 | 46 | end 47 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to ~/spec when you run 'ruby script/generate rspec' 2 | # from the project root directory. 3 | ENV["RAILS_ENV"] ||= 'test' 4 | require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) 5 | require 'spec/autorun' 6 | require 'spec/rails' 7 | 8 | # Requires supporting files with custom matchers and macros, etc, 9 | # in ./support/ and its subdirectories. 10 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} 11 | 12 | Spec::Runner.configure do |config| 13 | # If you're not using ActiveRecord you should remove these 14 | # lines, delete config/database.yml and disable :active_record 15 | # in your config/boot.rb 16 | config.use_transactional_fixtures = true 17 | config.use_instantiated_fixtures = false 18 | config.fixture_path = RAILS_ROOT + '/spec/fixtures/' 19 | 20 | # == Fixtures 21 | # 22 | # You can declare fixtures for each example_group like this: 23 | # describe "...." do 24 | # fixtures :table_a, :table_b 25 | # 26 | # Alternatively, if you prefer to declare them only once, you can 27 | # do so right here. Just uncomment the next line and replace the fixture 28 | # names with your fixtures. 29 | # 30 | # config.global_fixtures = :table_a, :table_b 31 | # 32 | # If you declare global fixtures, be aware that they will be declared 33 | # for all of your examples, even those that don't use them. 34 | # 35 | # You can also declare which fixtures to use (for example fixtures for test/fixtures): 36 | # 37 | # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' 38 | # 39 | # == Mock Framework 40 | # 41 | # RSpec uses it's own mocking framework by default. If you prefer to 42 | # use mocha, flexmock or RR, uncomment the appropriate line: 43 | # 44 | # config.mock_with :mocha 45 | # config.mock_with :flexmock 46 | # config.mock_with :rr 47 | # 48 | # == Notes 49 | # 50 | # For more information take a look at Spec::Runner::Configuration and Spec::Runner 51 | end 52 | -------------------------------------------------------------------------------- /spec/models/event_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') 2 | 3 | describe Event do 4 | before(:each) do 5 | @valid_attributes = { 6 | :user_id => 1, 7 | :title => "value for title", 8 | :priority => 1, 9 | :due => Time.now, 10 | :done => false, 11 | :created_at => Time.now, 12 | :updated_at => Time.now 13 | } 14 | 15 | @valid_event = Event.new(@valid_attributes) 16 | end 17 | 18 | it "should create a new instance given valid attributes" do 19 | Event.create!(@valid_attributes) 20 | end 21 | 22 | it "should require title" do 23 | Event.new(@valid_attributes.except(:title)).should have(1).error_on(:title) 24 | end 25 | 26 | it "should validate priority" do 27 | Event.new(@valid_attributes.merge({:priority => 5})).should have(1).error_on(:priority) 28 | end 29 | 30 | it "should mark and unmark as done" do 31 | event = Event.new(@valid_attributes.merge({:done => false})) 32 | event.mark_as_done 33 | event.done.should be_true 34 | event.unmark_as_done 35 | event.done.should be_false 36 | end 37 | 38 | end 39 | 40 | describe Event, ".fetch_for_period" do 41 | fixtures :events 42 | 43 | it "should return valid items for periods" do 44 | today = Date.today 45 | 46 | Event::fetch_for_period(today, today + 1).should have(1).items.kind_of(Event) 47 | Event::fetch_for_period(today, today.next_week + 1).should have(2).items.kind_of(Event) 48 | Event::fetch_for_period(today, today.next_month + 1).should have(3).items.kind_of(Event) 49 | Event::fetch_for_period(today, today.next_year + 1).should have(4).items.kind_of(Event) 50 | end 51 | 52 | it "list should be sorted by priority" do 53 | today = Date.today 54 | list = Event.fetch_for_period(today, today.next_year) 55 | list.should have(4).items.kind_of(Event) 56 | list.map(&:priority).should eql(list.map(&:priority).sort) 57 | end 58 | end 59 | 60 | -------------------------------------------------------------------------------- /spec/views/events/partials.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') 2 | 3 | describe "events/index.html.erb partials" do 4 | 5 | it "should have a correct quickie partial" do 6 | render :partial => "/events/quickie_new" 7 | 8 | response.should have_tag("form[action=?][method=post][onsubmit*=Ajax.Updater][onsubmit*=failure:'quickie_form']", create_quickie_events_path ) do 9 | with_tag("select#event_priority[name=?]", "event[priority]") do 10 | with_tag("option[value=?]", "1" ) 11 | with_tag("option[value=?]", "2" ) 12 | with_tag("option[value=?]", "3" ) 13 | end 14 | with_tag("input#event_title[name=?]", "event[title]") 15 | with_tag("select#event_due_1i[name=?]", "event[due(1i)]") 16 | with_tag("select#event_due_2i[name=?]", "event[due(2i)]") 17 | with_tag("select#event_due_3i[name=?]", "event[due(3i)]") 18 | end 19 | end 20 | 21 | it "should show unmarked list item" do 22 | mock_event = stub_model(Event, 23 | :id => "37", 24 | :priority => 1, 25 | :done => false 26 | ) 27 | render :partial => "/events/list_item", :locals => {:list_item => mock_event} 28 | response.should have_tag("input[type=checkbox][name=?][onclick*=Ajax.Request]", "cb_#{mock_event.id}") 29 | response.should have_tag("a[onclick*=Ajax.Request][onclick*=?]", edit_event_path(mock_event)) 30 | response.should have_tag("a[href=?][title='Delete item']", event_path(mock_event)) 31 | end 32 | 33 | it "should show marked list item" do 34 | mock_event = stub_model(Event, 35 | :id => "37", 36 | :title => "Event title", 37 | :done => true 38 | ) 39 | render :partial => "/events/list_item", :locals => {:list_item => mock_event} 40 | response.should have_tag("input[type=checkbox][checked=checked][name=?][onclick*=Ajax.Request]", "cb_#{mock_event.id}") 41 | response.should_not have_tag("a[onclick*=Ajax.Request][onclick*=?]", edit_event_path(mock_event)) 42 | response.should have_text(/Event title/) 43 | response.should_not have_tag("a[href=?][title='Delete item']", event_path(mock_event)) 44 | end 45 | end -------------------------------------------------------------------------------- /spec/routing/events_routing_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') 2 | 3 | describe EventsController do 4 | describe "route generation" do 5 | it "maps #index" do 6 | route_for(:controller => "events", :action => "index").should == "/events" 7 | end 8 | 9 | it "maps #index with period" do 10 | route_for(:controller => "events", :action => "index", :period => "week").should == "/events/period/week" 11 | end 12 | 13 | it "maps #new" do 14 | route_for(:controller => "events", :action => "new").should == "/events/new" 15 | end 16 | 17 | it "maps #show" do 18 | route_for(:controller => "events", :action => "show", :id => "1").should == "/events/1" 19 | end 20 | 21 | it "maps #edit" do 22 | route_for(:controller => "events", :action => "edit", :id => "1").should == "/events/1/edit" 23 | end 24 | 25 | it "maps #create" do 26 | route_for(:controller => "events", :action => "create").should == {:path => "/events", :method => :post} 27 | end 28 | 29 | it "maps #update" do 30 | route_for(:controller => "events", :action => "update", :id => "1").should == {:path =>"/events/1", :method => :put} 31 | end 32 | 33 | it "maps #destroy" do 34 | route_for(:controller => "events", :action => "destroy", :id => "1").should == {:path =>"/events/1", :method => :delete} 35 | end 36 | 37 | it "maps #done" do 38 | route_for(:controller => "events", :action => "done", :id => "1").should == {:path => "/events/1/done", :method => :post} 39 | end 40 | 41 | it "maps #create_quickie" do 42 | route_for(:controller => "events", :action => "create_quickie").should == {:path => "/events/create_quickie", :method => :post} 43 | end 44 | end 45 | 46 | describe "route recognition" do 47 | it "generates params for #index" do 48 | params_from(:get, "/events").should == {:controller => "events", :action => "index"} 49 | end 50 | 51 | it "generates params for #index with period" do 52 | params_from(:get, "/events/period/week").should == {:controller => "events", :action => "index", :period => "week"} 53 | end 54 | 55 | it "generates params for #new" do 56 | params_from(:get, "/events/new").should == {:controller => "events", :action => "new"} 57 | end 58 | 59 | it "generates params for #create" do 60 | params_from(:post, "/events").should == {:controller => "events", :action => "create"} 61 | end 62 | 63 | it "generates params for #show" do 64 | params_from(:get, "/events/1").should == {:controller => "events", :action => "show", :id => "1"} 65 | end 66 | 67 | it "generates params for #edit" do 68 | params_from(:get, "/events/1/edit").should == {:controller => "events", :action => "edit", :id => "1"} 69 | end 70 | 71 | it "generates params for #update" do 72 | params_from(:put, "/events/1").should == {:controller => "events", :action => "update", :id => "1"} 73 | end 74 | 75 | it "generates params for #destroy" do 76 | params_from(:delete, "/events/1").should == {:controller => "events", :action => "destroy", :id => "1"} 77 | end 78 | 79 | it "generates params for #done" do 80 | params_from(:post, "/events/1/done").should == {:controller => "events", :action => "done", :id => "1"} 81 | end 82 | 83 | it "generates params for #create_quickie" do 84 | params_from(:post, "/events/create_quickie").should == {:controller => "events", :action => "create_quickie"} 85 | end 86 | 87 | 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /app/controllers/events_controller.rb: -------------------------------------------------------------------------------- 1 | class EventsController < ApplicationController 2 | 3 | after_filter :discard_flash_if_xhr 4 | 5 | # GET /events 6 | # GET /events.xml 7 | def index 8 | nextday = future_date(params[:period]) 9 | @events = Event.fetch_for_period(Date.today, nextday) 10 | 11 | respond_to do |format| 12 | format.html # index.html.erb 13 | format.xml { render :xml => @events } 14 | end 15 | end 16 | 17 | # GET /events/1 18 | # GET /events/1.xml 19 | def show 20 | @event = Event.find(params[:id]) 21 | 22 | respond_to do |format| 23 | format.html # show.html.erb 24 | format.xml { render :xml => @event } 25 | format.js { 26 | render :update do |page| 27 | page.replace_html "event_#{@event.id}", :partial => "events/list_item", :locals => {:list_item => @event} 28 | end 29 | } 30 | end 31 | end 32 | 33 | # GET /events/new 34 | # GET /events/new.xml 35 | def new 36 | @event = Event.new 37 | 38 | respond_to do |format| 39 | format.html # new.html.erb 40 | format.xml { render :xml => @event } 41 | end 42 | end 43 | 44 | # GET /events/1/edit 45 | def edit 46 | @event = Event.find(params[:id]) 47 | respond_to do |format| 48 | format.html {} 49 | format.js { 50 | render :update do |page| 51 | page.replace_html "event_#{@event.id}", :partial => "events/quickie_edit" 52 | end 53 | } 54 | end 55 | end 56 | 57 | # POST /events 58 | # POST /events.xml 59 | def create 60 | @event = Event.new(params[:event]) 61 | 62 | respond_to do |format| 63 | if @event.save 64 | flash[:notice] = 'Event was successfully created.' 65 | format.html { redirect_to(@event) } 66 | format.xml { render :xml => @event, :status => :created, :location => @event } 67 | else 68 | format.html { render :action => "new" } 69 | format.xml { render :xml => @event.errors, :status => :unprocessable_entity } 70 | end 71 | end 72 | end 73 | 74 | def create_quickie 75 | @event = Event.new(params[:event]) 76 | 77 | respond_to do |format| 78 | if @event.save 79 | flash[:notice] = 'Event was successfully created.' 80 | format.html { 81 | render :update do |page| 82 | page.insert_html :top, "events_list", :partial => "events/list_item", :locals => {:list_item => @event} 83 | page.visual_effect :highlight, "event_#{@event.id}" 84 | @event.title = "" 85 | @event.priority = 1 86 | @event.due = Date.today 87 | page.replace_html "quickie_form", :partial => "events/quickie_new" 88 | page["notice"].replace_html flash[:notice] 89 | end 90 | } 91 | else 92 | format.html { 93 | render :partial => "events/quickie_new", :status => 444, :layout => false 94 | } 95 | format.xml { render :xml => @event.errors, :status => :unprocessable_entity } 96 | end 97 | end 98 | end 99 | 100 | def done 101 | @event = Event.find(params[:id]) 102 | (@event.done) ? @event.unmark_as_done : @event.mark_as_done 103 | 104 | respond_to do |format| 105 | flash[:notice] = 'Event was updated.' 106 | format.js { 107 | render :update do |page| 108 | page.replace_html "event_#{@event.id}", :partial => "/events/list_item", :locals => {:list_item => @event} 109 | page.replace_html "notice", flash[:notice] 110 | end 111 | } 112 | end 113 | rescue ActiveRecord::RecordNotFound 114 | respond_to do |format| 115 | flash[:notice] = 'Event was NOT updated.' 116 | format.js { 117 | render :update do |page| 118 | page["notice"].replace_html flash[:notice] 119 | end 120 | } 121 | end 122 | end 123 | 124 | # PUT /events/1 125 | # PUT /events/1.xml 126 | def update 127 | @event = Event.find(params[:id]) 128 | 129 | respond_to do |format| 130 | if @event.update_attributes(params[:event]) 131 | flash[:notice] = 'Event was successfully updated.' 132 | format.html { redirect_to(@event) } 133 | format.xml { head :ok } 134 | format.js { 135 | render :update do |page| 136 | page.replace_html "event_#{@event.id}", :partial => "/events/list_item", :locals => {:list_item => @event} 137 | page["notice"].replace_html flash[:notice] 138 | end 139 | } 140 | else 141 | format.html { render :action => "edit" } 142 | format.xml { render :xml => @event.errors, :status => :unprocessable_entity } 143 | format.js { 144 | render :partial => "/events/quickie_edit", :status => 444, :layout => false 145 | } 146 | end 147 | end 148 | end 149 | 150 | # DELETE /events/1 151 | # DELETE /events/1.xml 152 | def destroy 153 | @event = Event.find(params[:id]) 154 | if @event.destroy 155 | flash[:notice] = 'Event was successfully deleted.' 156 | end 157 | 158 | respond_to do |format| 159 | format.html { redirect_to(events_url) } 160 | format.xml { head :ok } 161 | end 162 | end 163 | 164 | def future_date(period) 165 | today = Date.today 166 | 167 | case period 168 | when 'today' 169 | nextday = today + 1 170 | when 'week' 171 | nextday = today.next_week 172 | when 'month' 173 | nextday = today.next_month 174 | when 'year' 175 | nextday = today.next_year 176 | else 177 | nextday = today + 1 178 | end 179 | 180 | nextday 181 | end 182 | 183 | protected 184 | def discard_flash_if_xhr 185 | flash.discard if request.xhr? 186 | end 187 | 188 | end 189 | -------------------------------------------------------------------------------- /spec/controllers/events_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') 2 | 3 | describe EventsController do 4 | 5 | def mock_event(stubs={}) 6 | @mock_event ||= mock_model(Event, stubs) 7 | end 8 | 9 | def mock_valid_event(stubs={}) 10 | mock_event({:id => "37", :due => Date.today, :priority => 1, :title => "Event", :done => false}.merge!(stubs)) 11 | end 12 | 13 | describe "GET index" do 14 | it "populates events for period, default is 'today'" do 15 | Event.should_receive(:fetch_for_period).with(Date.today, Date.today + 1).and_return([mock_event(:id => 1)]) 16 | get :index 17 | assigns[:events].should == [mock_event] 18 | end 19 | 20 | it "populates events for period, default is 'today' with wrong param" do 21 | Event.should_receive(:fetch_for_period).with(Date.today, Date.today + 1).and_return([mock_event(:id => 1)]) 22 | get :index, :period => 'foo' 23 | assigns[:events].should == [mock_event] 24 | end 25 | 26 | it "populates events for today" do 27 | Event.should_receive(:fetch_for_period).with(Date.today, Date.today + 1).and_return([mock_event(:id => 1)]) 28 | get :index, :period => 'today' 29 | assigns[:events].should == [mock_event] 30 | end 31 | 32 | it "populates event for next week" do 33 | Event.should_receive(:fetch_for_period).with(Date.today, Date.today.next_week).and_return([mock_event(:id => 1)]) 34 | get :index, :period => 'week' 35 | assigns[:events].should == [mock_event] 36 | end 37 | 38 | it "populates event for next month" do 39 | Event.should_receive(:fetch_for_period).with(Date.today, Date.today.next_month).and_return([mock_event(:id => 1)]) 40 | get :index, :period => 'month' 41 | assigns[:events].should == [mock_event] 42 | end 43 | 44 | it "populates event for next year" do 45 | Event.should_receive(:fetch_for_period).with(Date.today, Date.today.next_year).and_return([mock_event(:id => 1)]) 46 | get :index, :period => 'year' 47 | assigns[:events].should == [mock_event] 48 | end 49 | end 50 | 51 | describe "GET show" do 52 | it "assigns the requested event as @event" do 53 | Event.stub!(:find).with("37").and_return(mock_event) 54 | get :show, :id => "37" 55 | assigns[:event].should equal(mock_event) 56 | end 57 | end 58 | 59 | describe "GET ajax show" do 60 | it "assigns the requested event as @event" do 61 | Event.stub!(:find).with("37").and_return(mock_valid_event) 62 | xhr :get, :show, :id => "37" 63 | response.should have_rjs(:replace_html, "event_37") 64 | end 65 | end 66 | 67 | describe "GET new" do 68 | it "assigns a new event as @event" do 69 | Event.stub!(:new).and_return(mock_event) 70 | get :new 71 | assigns[:event].should equal(mock_event) 72 | end 73 | end 74 | 75 | describe "GET edit" do 76 | it "assigns the requested event as @event" do 77 | Event.stub!(:find).with("37").and_return(mock_event) 78 | get :edit, :id => "37" 79 | assigns[:event].should equal(mock_event) 80 | end 81 | end 82 | 83 | describe "POST create" do 84 | describe "with valid params" do 85 | it "assigns a newly created event as @event" do 86 | Event.stub!(:new).with({'these' => 'params'}).and_return(mock_event(:save => true)) 87 | post :create, :event => {:these => 'params'} 88 | assigns[:event].should equal(mock_event) 89 | end 90 | 91 | it "redirects to the created event" do 92 | Event.stub!(:new).and_return(mock_event(:save => true)) 93 | post :create, :event => {} 94 | response.should redirect_to(event_url(mock_event)) 95 | end 96 | end 97 | 98 | describe "with invalid params" do 99 | it "assigns a newly created but unsaved event as @event" do 100 | Event.stub!(:new).with({'these' => 'params'}).and_return(mock_event(:save => false)) 101 | post :create, :event => {:these => 'params'} 102 | assigns[:event].should equal(mock_event) 103 | end 104 | 105 | it "re-renders the 'new' template" do 106 | Event.stub!(:new).and_return(mock_event(:save => false)) 107 | post :create, :event => {} 108 | response.should render_template('new') 109 | end 110 | end 111 | 112 | end 113 | 114 | describe "POST create quickie" do 115 | describe "with valid params" do 116 | it "should assign a newly created event to @event and insert into list" do 117 | Event.stub!(:new).with({'these' => 'params'}).and_return(mock_event(:save => true, :priority => 1, :title => "Event", :due => Date.today, :done => false)) 118 | 119 | # Clear quickie form 120 | @mock_event.should_receive(:priority=).with(1) 121 | @mock_event.should_receive(:title=).with("") 122 | @mock_event.should_receive(:due=).with(Date.today) 123 | 124 | post :create_quickie, :event => {:these => 'params'} 125 | # assigns[:event].should equal(mock_event) 126 | 127 | response.should have_rjs(:insert_html, "events_list") 128 | response.should have_rjs(:replace_html, "quickie_form") 129 | end 130 | end 131 | 132 | describe "with invalid params" do 133 | it "should assign a newly created event to @event and insert into list" do 134 | Event.stub!(:new).with({'these' => 'params'}).and_return(mock_event(:save => false)) 135 | controller.should_receive(:render).with(:partial => "events/quickie_new", :status => 444, :layout => false) 136 | 137 | post :create_quickie, :event => {:these => 'params'} 138 | assigns[:event].should equal(mock_event) 139 | end 140 | end 141 | end 142 | 143 | describe "PUT update" do 144 | 145 | describe "with valid params" do 146 | it "updates the requested event" do 147 | Event.should_receive(:find).with("37").and_return(mock_event) 148 | mock_event.should_receive(:update_attributes).with({'these' => 'params'}) 149 | put :update, :id => "37", :event => {:these => 'params'} 150 | end 151 | 152 | it "assigns the requested event as @event" do 153 | Event.stub!(:find).and_return(mock_event(:update_attributes => true)) 154 | put :update, :id => "1" 155 | assigns[:event].should equal(mock_event) 156 | end 157 | 158 | it "redirects to the event" do 159 | Event.stub!(:find).and_return(mock_event(:update_attributes => true)) 160 | put :update, :id => "1" 161 | response.should redirect_to(event_url(mock_event)) 162 | end 163 | end 164 | 165 | describe "with invalid params" do 166 | it "updates the requested event" do 167 | Event.should_receive(:find).with("37").and_return(mock_event) 168 | mock_event.should_receive(:update_attributes).with({'these' => 'params'}) 169 | put :update, :id => "37", :event => {:these => 'params'} 170 | end 171 | 172 | it "assigns the event as @event" do 173 | Event.stub!(:find).and_return(mock_event(:update_attributes => false)) 174 | put :update, :id => "1" 175 | assigns[:event].should equal(mock_event) 176 | end 177 | 178 | it "re-renders the 'edit' template" do 179 | Event.stub!(:find).and_return(mock_event(:update_attributes => false)) 180 | put :update, :id => "1" 181 | response.should render_template('edit') 182 | end 183 | end 184 | 185 | end 186 | 187 | describe "GET ajax edit" do 188 | it "assigns the requested event as @event" do 189 | Event.stub!(:find).with("37").and_return(mock_event(:id => 37, :priority => 1, :title => "Event", :due => Date.today)) 190 | xhr :get, :edit, :id => "37" 191 | assigns[:event].should equal(mock_event) 192 | response.should have_rjs(:replace_html, "event_37") 193 | end 194 | end 195 | 196 | describe "PUT ajax update" do 197 | describe "with valid params" do 198 | it "should update requested event" do 199 | Event.should_receive(:find).with("37").and_return(mock_valid_event(:update_attributes => true)) 200 | xhr :put, :update, :id => "37", :event => {"title" => 'Event title'} 201 | response.should have_rjs(:replace_html) 202 | response.should be_success 203 | end 204 | end 205 | 206 | describe "with invalid params" do 207 | it "should not update requested event" do 208 | Event.should_receive(:find).with("37").and_return(mock_valid_event(:update_attributes => false)) 209 | xhr :put, :update, :id => "37", :event => {:title => 'params'} 210 | response.status.should eql("444") 211 | end 212 | end 213 | end 214 | 215 | describe "POST done update" do 216 | it "should update requested event - mark as done" do 217 | Event.should_receive(:find).with("37").and_return(mock_valid_event) 218 | @mock_event.should_receive(:mark_as_done).and_return(true) 219 | xhr :post, :done, :id => "37" 220 | response.should be_success 221 | response.should have_rjs(:replace_html) 222 | end 223 | 224 | it "should handle wrong param" do 225 | put :done, :id => 'foo' 226 | response.should be_success 227 | response.should_not have_rjs(:replace_html) 228 | end 229 | 230 | it "should update requested event - unmark as done" do 231 | Event.should_receive(:find).with("37").and_return(mock_event(:id => "37", :due => Date.today, :priority => 1, :title => "Event", :done => true)) 232 | @mock_event.should_receive(:unmark_as_done).and_return(true) 233 | xhr :post, :done, :id => "37" 234 | response.should be_success 235 | response.should have_rjs(:replace_html) 236 | end 237 | 238 | end 239 | 240 | describe "DELETE destroy" do 241 | it "destroys the requested event" do 242 | Event.should_receive(:find).with("37").and_return(mock_event) 243 | mock_event.should_receive(:destroy) 244 | delete :destroy, :id => "37" 245 | end 246 | 247 | it "redirects to the events list" do 248 | Event.stub!(:find).and_return(mock_event(:destroy => true)) 249 | delete :destroy, :id => "1" 250 | response.should redirect_to(events_url) 251 | end 252 | end 253 | 254 | end 255 | --------------------------------------------------------------------------------