diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-05-12 13:50:18 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-05-24 18:55:38 +0200 |
commit | b158deb751714013e730fae449f9e3d9fa3dce00 (patch) | |
tree | e4f02f07bbf9e1538248655de321cd22af3caa9c | |
parent | Start using factory_girl (diff) | |
download | council-webapp-b158deb751714013e730fae449f9e3d9fa3dce00.tar.gz council-webapp-b158deb751714013e730fae449f9e3d9fa3dce00.tar.bz2 council-webapp-b158deb751714013e730fae449f9e3d9fa3dce00.zip |
Agenda model
-rw-r--r-- | site/app/controllers/agendas_controller.rb | 7 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 28 | ||||
-rw-r--r-- | site/app/models/guest.rb | 4 | ||||
-rw-r--r-- | site/config/hobo_routes.rb | 10 | ||||
-rw-r--r-- | site/db/schema.rb | 8 | ||||
-rw-r--r-- | site/features/agendas.feature | 15 | ||||
-rw-r--r-- | site/features/step_definitions/agenda_steps.rb | 12 | ||||
-rw-r--r-- | site/features/step_definitions/irc_nick_steps.rb | 2 | ||||
-rw-r--r-- | site/features/step_definitions/within_steps.rb | 4 | ||||
-rw-r--r-- | site/spec/factories.rb | 13 | ||||
-rw-r--r-- | site/spec/models/agenda_spec.rb | 32 | ||||
-rw-r--r-- | site/spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | site/spec/support/users_factory.rb | 21 |
13 files changed, 155 insertions, 2 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb new file mode 100644 index 0000000..438fff7 --- /dev/null +++ b/site/app/controllers/agendas_controller.rb @@ -0,0 +1,7 @@ +class AgendasController < ApplicationController + + hobo_model_controller + + auto_actions :all + +end diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb new file mode 100644 index 0000000..a6fe828 --- /dev/null +++ b/site/app/models/agenda.rb @@ -0,0 +1,28 @@ +class Agenda < ActiveRecord::Base + + hobo_model # Don't put anything above this + + fields do + meeting_time :datetime + timestamps + end + + # --- Permissions --- # + + def create_permitted? + false + end + + def update_permitted? + acting_user.council_member? || acting_user.administrator? + end + + def destroy_permitted? + false + end + + def view_permitted?(field) + true + end + +end diff --git a/site/app/models/guest.rb b/site/app/models/guest.rb index b7b3230..cce1de4 100644 --- a/site/app/models/guest.rb +++ b/site/app/models/guest.rb @@ -4,4 +4,8 @@ class Guest < Hobo::Model::Guest false end + def council_member? + false + end + end diff --git a/site/config/hobo_routes.rb b/site/config/hobo_routes.rb index dde7225..7035490 100644 --- a/site/config/hobo_routes.rb +++ b/site/config/hobo_routes.rb @@ -26,4 +26,14 @@ Council::Application.routes.draw do get 'logout(.:format)' => 'users#logout', :as => 'user_logout' match 'forgot_password(.:format)' => 'users#forgot_password', :as => 'user_forgot_password' + + # Resource routes for controller "agendas" + get 'agendas(.:format)' => 'agendas#index', :as => 'agendas' + get 'agendas/new(.:format)', :as => 'new_agenda' + get 'agendas/:id/edit(.:format)' => 'agendas#edit', :as => 'edit_agenda' + get 'agendas/:id(.:format)' => 'agendas#show', :as => 'agenda', :constraints => { :id => %r([^/.?]+) } + post 'agendas(.:format)' => 'agendas#create', :as => 'create_agenda' + put 'agendas/:id(.:format)' => 'agendas#update', :as => 'update_agenda', :constraints => { :id => %r([^/.?]+) } + delete 'agendas/:id(.:format)' => 'agendas#destroy', :as => 'destroy_agenda', :constraints => { :id => %r([^/.?]+) } + end diff --git a/site/db/schema.rb b/site/db/schema.rb index 433a0c7..812d821 100644 --- a/site/db/schema.rb +++ b/site/db/schema.rb @@ -10,7 +10,13 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110520150447) do +ActiveRecord::Schema.define(:version => 20110520150527) do + + create_table "agendas", :force => true do |t| + t.datetime "meeting_time" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "users", :force => true do |t| t.string "salt", :limit => 40 diff --git a/site/features/agendas.feature b/site/features/agendas.feature new file mode 100644 index 0000000..77267a5 --- /dev/null +++ b/site/features/agendas.feature @@ -0,0 +1,15 @@ +Feature: Agendas + In order to manage meetings + I want to have agendas + + Scenario: View agendas listing as a guest + When I am on the homepage + And I follow "Agendas" + Then I should not see "Agenda" in the content body + + Given an agenda + When I follow "Agendas" + Then I should see "Agenda" in the agendas collection + + When I follow link to first agenda + Then I should see current date as meeting time diff --git a/site/features/step_definitions/agenda_steps.rb b/site/features/step_definitions/agenda_steps.rb new file mode 100644 index 0000000..95c7406 --- /dev/null +++ b/site/features/step_definitions/agenda_steps.rb @@ -0,0 +1,12 @@ +Given /^an agenda$/ do + Agenda.new(:meeting_time => Time.now).save! +end + +Then /^I should see current date as meeting time$/ do + Then "I should see \"#{Time.now.strftime("%Y-%m-%d")}\" as meeting time" +end + +When /^I follow link to first agenda$/ do + link_text = page.find(:xpath, "//a[contains(@class, 'agenda-link')]").text + When "I follow \"#{link_text}\"" +end diff --git a/site/features/step_definitions/irc_nick_steps.rb b/site/features/step_definitions/irc_nick_steps.rb index acaa4f8..5daf44f 100644 --- a/site/features/step_definitions/irc_nick_steps.rb +++ b/site/features/step_definitions/irc_nick_steps.rb @@ -1,7 +1,7 @@ When /^I fill in example user registration data$/ do When "I fill in the following:", table(%{ |user_name|examle| - |user_email_address|example@example.com| + |user_email|example@example.com| |user_irc_nick|example| |user_password|Example| |user_password_confirmation|Example| diff --git a/site/features/step_definitions/within_steps.rb b/site/features/step_definitions/within_steps.rb index 76b0ad6..3f42f37 100644 --- a/site/features/step_definitions/within_steps.rb +++ b/site/features/step_definitions/within_steps.rb @@ -1,6 +1,10 @@ { 'in the notices' => '.flash.notice', 'in the errors' => '.error-messages', + 'in the content body' => '.content-body', + 'in the agendas collection' => '.collection.agendas', + 'as empty collection message' => '.empty-collection-message', + 'as meeting time' => '.meeting-time-view', 'as the user nick' => '.user-irc-nick' }. each do |within, selector| diff --git a/site/spec/factories.rb b/site/spec/factories.rb new file mode 100644 index 0000000..a7256c0 --- /dev/null +++ b/site/spec/factories.rb @@ -0,0 +1,13 @@ +Factory.sequence :user do |n| + "user-#{n}" +end + +Factory.define :user, :class => User do |u| + u.name { Factory.next(:user) } + u.irc_nick { Factory.next(:user) } + u.email { |u| "#{u.name}@example.com" } +end + +Factory.define :guest do |g|; end + +Factory.define :agenda do |a|; end diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb new file mode 100644 index 0000000..9fd3c68 --- /dev/null +++ b/site/spec/models/agenda_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Agenda do + it "shouldn't allow anyone to create and destroy" do + agendas = [Agenda.new, Factory(:agenda)] + for a in agendas + for u in users_factory(AllRoles) + a.should_not be_creatable_by(u) + a.should_not be_destroyable_by(u) + end + end + end + + it "shouldn allow everybody to view" do + agendas = [Agenda.new, Factory(:agenda)] + for a in agendas + for u in users_factory(AllRoles) + a.should be_viewable_by(u) + end + end + end + + it "should allow only administrators and council members to edit and update" do + agendas = [Agenda.new, Factory(:agenda)] + for a in agendas + for u in users_factory(AllRoles) + a.should_not be_editable_by(u) + a.should_not be_updatable_by(u) + end + end + end +end diff --git a/site/spec/spec_helper.rb b/site/spec/spec_helper.rb index 20a45b7..53f0ed3 100644 --- a/site/spec/spec_helper.rb +++ b/site/spec/spec_helper.rb @@ -1,6 +1,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' +require 'factories.rb' RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) environment_path = File.expand_path(File.join(RAILS_ROOT, 'config', 'environment')) diff --git a/site/spec/support/users_factory.rb b/site/spec/support/users_factory.rb new file mode 100644 index 0000000..40c715b --- /dev/null +++ b/site/spec/support/users_factory.rb @@ -0,0 +1,21 @@ +def users_factory(*roles) + roles.flatten! + r = [] + for role in roles + case role + when :guest + r.push Guest.new + when :user + r.push Factory(:user) + when :council + r.push Factory(:user, :council_member => true) + when :admin + r.push Factory(:user, :administrator => true) + when :council_admin + r.push Factory(:user, :council_member => true, :administrator => true) + end + end + (r.count < 2) ? r.first : r +end + +AllRoles = [:guest, :user, :council, :admin, :council_admin] |