public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/council-webapp:master commit in: site/spec/support/, site/db/, site/features/, site/config/, ...
@ 2011-05-24 16:58 Petteri Räty
  0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-05-24 16:58 UTC (permalink / raw
  To: gentoo-commits

commit:     b158deb751714013e730fae449f9e3d9fa3dce00
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Thu May 12 11:50:18 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue May 24 16:55:38 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=b158deb7

Agenda model

---
 site/app/controllers/agendas_controller.rb       |    7 +++++
 site/app/models/agenda.rb                        |   28 +++++++++++++++++++
 site/app/models/guest.rb                         |    4 +++
 site/config/hobo_routes.rb                       |   10 +++++++
 site/db/schema.rb                                |    8 +++++-
 site/features/agendas.feature                    |   15 ++++++++++
 site/features/step_definitions/agenda_steps.rb   |   12 ++++++++
 site/features/step_definitions/irc_nick_steps.rb |    2 +-
 site/features/step_definitions/within_steps.rb   |    4 +++
 site/spec/factories.rb                           |   13 +++++++++
 site/spec/models/agenda_spec.rb                  |   32 ++++++++++++++++++++++
 site/spec/spec_helper.rb                         |    1 +
 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]



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-24 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-24 16:58 [gentoo-commits] proj/council-webapp:master commit in: site/spec/support/, site/db/, site/features/, site/config/, Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox