aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Xie <xieconnect@gmail.com>2010-07-28 13:33:40 +0800
committerHans de Graaff <hans@degraaff.org>2010-08-09 07:36:05 +0200
commit61a3a8bcb2c752c435ee95e97cdefee22d83d2a8 (patch)
treec1256af7b1c3025e5712803720fa302e91b7a87a
parentFix indention in User model (diff)
downloadcouncil-webapp-61a3a8bcb2c752c435ee95e97cdefee22d83d2a8.tar.gz
council-webapp-61a3a8bcb2c752c435ee95e97cdefee22d83d2a8.tar.bz2
council-webapp-61a3a8bcb2c752c435ee95e97cdefee22d83d2a8.zip
GLEP work flow support implemented and tested
Users need to make sure the agenda selected is not too near
-rw-r--r--app/controllers/gleps_controller.rb7
-rw-r--r--app/models/agenda.rb6
-rw-r--r--app/models/glep.rb40
-rw-r--r--app/models/user.rb7
-rw-r--r--app/views/taglibs/auto/rapid/cards.dryml11
-rw-r--r--app/views/taglibs/auto/rapid/forms.dryml12
-rw-r--r--app/views/taglibs/auto/rapid/pages.dryml124
-rw-r--r--db/migrate/20100606080751_create_gleps.rb18
-rw-r--r--db/seeds.rb13
-rw-r--r--features/glep.feature23
-rw-r--r--features/step_definitions/glep_steps.rb5
-rw-r--r--spec/fixtures/agendas.yml2
-rw-r--r--spec/fixtures/gleps.yml10
-rw-r--r--spec/models/glep_spec.rb25
14 files changed, 300 insertions, 3 deletions
diff --git a/app/controllers/gleps_controller.rb b/app/controllers/gleps_controller.rb
new file mode 100644
index 0000000..85f5310
--- /dev/null
+++ b/app/controllers/gleps_controller.rb
@@ -0,0 +1,7 @@
+class GlepsController < ApplicationController
+
+ hobo_model_controller
+
+ auto_actions :all
+
+end
diff --git a/app/models/agenda.rb b/app/models/agenda.rb
index b806a7a..d542f38 100644
--- a/app/models/agenda.rb
+++ b/app/models/agenda.rb
@@ -12,9 +12,15 @@ class Agenda < ActiveRecord::Base
belongs_to :owner, :class_name => 'User', :creator => true
has_many :agenda_items, :dependent => :destroy
+ has_many :gleps, :dependent => :destroy
validates_presence_of :owner
+
+ def too_close
+ self.start_at < 2.weeks.from_now
+ end
+
# --- Permissions --- #
never_show :owner
diff --git a/app/models/glep.rb b/app/models/glep.rb
new file mode 100644
index 0000000..e7f4c01
--- /dev/null
+++ b/app/models/glep.rb
@@ -0,0 +1,40 @@
+class Glep < ActiveRecord::Base
+
+ hobo_model # Don't put anything above this
+
+ fields do
+ name :string, :null => false
+ description :text
+ timestamps
+ end
+
+ belongs_to :owner, :class_name => 'User', :creator => true
+ belongs_to :agenda
+
+ validates_presence_of :owner
+
+ # agenda must be selected
+ validates_presence_of :agenda
+ validate :agenda_not_too_close
+
+
+ # --- Permissions --- #
+
+ def create_permitted?
+ permitted_for_roles(:admin, :council_member, :developer)
+ end
+
+ multi_permission(:update, :destroy) do
+ permitted_for_roles(:admin, :council_member)
+ end
+
+ def view_permitted?(field)
+ true
+ end
+
+protected
+
+ def agenda_not_too_close
+ errors.add_to_base('Agenda selected should not be too close') if self.agenda.too_close
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index d43c6f7..2aec581 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -9,8 +9,11 @@ class User < ActiveRecord::Base
timestamps
end
- has_many :votes, :foreign_key => 'owner_id',
- :dependent => :destroy, :order => 'created_at DESC'
+ conditions = {:foreign_key => 'owner_id',
+ :dependent => :destroy, :order => 'created_at DESC'}
+
+ has_many :votes, conditions
+ has_many :gleps, conditions
# This gives admin rights to the first sign-up.
# Just remove it if you don't want that
diff --git a/app/views/taglibs/auto/rapid/cards.dryml b/app/views/taglibs/auto/rapid/cards.dryml
index 055d135..eb89d9d 100644
--- a/app/views/taglibs/auto/rapid/cards.dryml
+++ b/app/views/taglibs/auto/rapid/cards.dryml
@@ -25,6 +25,17 @@
</card>
</def>
+<def tag="card" for="Glep">
+ <card class="glep" param="default" merge>
+ <header: param>
+ <h4 param="heading"><a><name/></a></h4>
+ </header:>
+ <body: param>
+ <a:owner param="creator-link"/>
+ </body:>
+ </card>
+</def>
+
<def tag="card" for="Question">
<card class="question" param="default" merge>
<header: param>
diff --git a/app/views/taglibs/auto/rapid/forms.dryml b/app/views/taglibs/auto/rapid/forms.dryml
index 3bd585d..8424a0d 100644
--- a/app/views/taglibs/auto/rapid/forms.dryml
+++ b/app/views/taglibs/auto/rapid/forms.dryml
@@ -46,6 +46,18 @@
+<def tag="form" for="Glep">
+ <form merge param="default">
+ <error-messages param/>
+ <field-list fields="name, description, agenda, owner" param/>
+ <div param="actions">
+ <submit label="#{ht 'gleps.actions.save', :default=>['Save']}" param/><or-cancel param="cancel"/>
+ </div>
+ </form>
+</def>
+
+
+
<def tag="form" for="Question">
<form merge param="default">
<error-messages param/>
diff --git a/app/views/taglibs/auto/rapid/pages.dryml b/app/views/taglibs/auto/rapid/pages.dryml
index c8636ea..8732cfc 100644
--- a/app/views/taglibs/auto/rapid/pages.dryml
+++ b/app/views/taglibs/auto/rapid/pages.dryml
@@ -7,6 +7,7 @@
<nav-item href="#{base_url}/">Home</nav-item>
<nav-item with="&Agenda"><ht key="agendas.nav_item">Agendas</ht></nav-item>
<nav-item with="&AgendaItem"><ht key="agenda_items.nav_item">Agenda Items</ht></nav-item>
+ <nav-item with="&Glep"><ht key="gleps.nav_item">Gleps</ht></nav-item>
<nav-item with="&Question"><ht key="questions.nav_item">Questions</ht></nav-item>
</navigation>
</def>
@@ -315,6 +316,129 @@
+<!-- ====== Glep Pages ====== -->
+
+<def tag="index-page" for="Glep">
+ <page merge title="#{ht 'gleps.index.title', :default=>['Gleps'] }">
+ <body: class="index-page glep" param/>
+
+ <content: param>
+ <header param="content-header">
+ <h2 param="heading">
+ <ht key="gleps.index.heading">
+ Gleps
+ </ht>
+ </h2>
+
+ <p param="count" if>
+ <ht key="gleps.collection.count" count="&this.size">
+ There <count prefix="are"/>
+ </ht>
+ </p>
+ </header>
+
+ <section param="content-body">
+ <a action="new" to="&model" param="new-link">
+ <ht key="gleps.actions.new">New Glep</ht>
+ </a>
+
+ <page-nav param="top-page-nav"/>
+
+ <collection param/>
+
+ <page-nav param="bottom-page-nav"/>
+
+
+ </section>
+ </content:>
+ </page>
+</def>
+
+
+<def tag="new-page" for="Glep">
+ <page merge title="#{ht 'gleps.new.title', :default=>[' New Glep'] }">
+ <body: class="new-page glep" param/>
+
+ <content: param>
+ <section param="content-header">
+ <h2 param="heading">
+ <ht key="gleps.new.heading">
+ New Glep
+ </ht>
+ </h2>
+ </section>
+
+ <section param="content-body">
+ <form param>
+ <submit: label="#{ht 'gleps.actions.create', :default=>['Create Glep']}"/>
+ </form>
+ </section>
+ </content:>
+ </page>
+</def>
+
+
+<def tag="show-page" for="Glep">
+ <page merge title="#{ht 'gleps.show.title', :default=>['Glep'] }">
+
+ <body: class="show-page glep" param/>
+
+ <content: param>
+ <header param="content-header">
+ <h2 param="heading">
+ <ht key="gleps.show.heading" name="&this.respond_to?(:name) ? this.name : ''">
+ <name/>
+ </ht>
+ </h2>
+
+ <record-flags fields="" param/>
+
+ <a:owner param="creator-link"/>
+
+ <a action="edit" if="&can_edit?" param="edit-link">
+ <ht key="gleps.actions.edit" name="&this.respond_to?(:name) ? this.name : ''">
+ Edit Glep
+ </ht>
+ </a>
+ </header>
+
+ <section param="content-body">
+ <view:description param="description"/>
+ <field-list fields="agenda" param/>
+ </section>
+ </content:>
+
+ </page>
+</def>
+
+
+<def tag="edit-page" for="Glep">
+ <page merge title="#{ht 'gleps.edit.title', :default=>['Edit Glep'] }">
+
+ <body: class="edit-page glep" param/>
+
+ <content:>
+ <section param="content-header">
+ <h2 param="heading">
+ <ht key="gleps.edit.heading" name="&this.respond_to?(:name) ? this.name : ''">
+ Edit <type-name/>
+ </ht>
+ </h2>
+ <delete-button label="#{ht 'gleps.actions.delete', :default=>['Remove This Glep']}" param/>
+ </section>
+
+ <section param="content-body">
+ <form param/>
+ </section>
+ </content:>
+
+ </page>
+</def>
+
+
+
+
+
<!-- ====== Question Pages ====== -->
<def tag="index-page" for="Question">
diff --git a/db/migrate/20100606080751_create_gleps.rb b/db/migrate/20100606080751_create_gleps.rb
new file mode 100644
index 0000000..2061d74
--- /dev/null
+++ b/db/migrate/20100606080751_create_gleps.rb
@@ -0,0 +1,18 @@
+class CreateGleps < ActiveRecord::Migration
+ def self.up
+ create_table :gleps do |t|
+ t.string :name, :null => false
+ t.text :description
+ t.datetime :created_at
+ t.datetime :updated_at
+ t.integer :owner_id
+ t.integer :agenda_id
+ end
+ add_index :gleps, [:owner_id]
+ add_index :gleps, [:agenda_id]
+ end
+
+ def self.down
+ drop_table :gleps
+ end
+end
diff --git a/db/seeds.rb b/db/seeds.rb
index 0fff605..3bcecf6 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -63,3 +63,16 @@ agenda_items = AgendaItem.create([
:description => 'agenda item 2',
:owner_id => users[1].id}
])
+
+puts 'adding gleps...'
+gleps = Glep.create([
+ { :name => 'glep1',
+ :description => 'glep1',
+ :agenda => agendas[0],
+ :owner_id => users[1].id},
+
+ { :name => 'glep2',
+ :description => 'glep2',
+ :agenda => agendas[0],
+ :owner_id => users[1].id},
+])
diff --git a/features/glep.feature b/features/glep.feature
new file mode 100644
index 0000000..3458dcf
--- /dev/null
+++ b/features/glep.feature
@@ -0,0 +1,23 @@
+Feature: GLEP work flow
+ As a council member
+ I want the webapp to track GLEP submissions
+ so that due attention is paid to them
+
+ Background: Developer with a GLEP
+ Given I am logged in as a developer
+ When I go to the home page
+ And I follow "Gleps"
+ And I follow "New Glep"
+ And I fill in "Name" with "glep_test_name"
+
+ Scenario: Next meeting over 2 weeks from now
+ When I select "Go to the Zoo" from "glep[agenda_id]"
+ And I press "Create Glep"
+ Then I should see "successfully"
+ When I visit glep "glep_test_name"
+ Then I should see "Go to the Zoo"
+
+ Scenario: Next meeting under 2 weeks from now
+ When I select "hosting a party" from "glep[agenda_id]"
+ And I press "Create Glep"
+ Then I should see "too close"
diff --git a/features/step_definitions/glep_steps.rb b/features/step_definitions/glep_steps.rb
new file mode 100644
index 0000000..0e08155
--- /dev/null
+++ b/features/step_definitions/glep_steps.rb
@@ -0,0 +1,5 @@
+When /^I visit glep "([^\"]*)"$/ do |glep_name|
+ When 'I go to the home page'
+ And 'I follow "Gleps"'
+ And %Q{I follow "#{glep_name}"}
+end
diff --git a/spec/fixtures/agendas.yml b/spec/fixtures/agendas.yml
index 141c7cb..fc0631d 100644
--- a/spec/fixtures/agendas.yml
+++ b/spec/fixtures/agendas.yml
@@ -7,7 +7,7 @@ agenda_one:
agenda_two:
name: hosting a party
description: HIT
- start_at: <%= 15.days.from_now %>
+ start_at: <%= 5.days.from_now %>
end_at: <%= 16.days.from_now %>
owner: council_member
agenda_test_name:
diff --git a/spec/fixtures/gleps.yml b/spec/fixtures/gleps.yml
new file mode 100644
index 0000000..8ad251c
--- /dev/null
+++ b/spec/fixtures/gleps.yml
@@ -0,0 +1,10 @@
+glep_one:
+ name: glep1
+ description: glep 1
+ agenda: agenda_one
+ owner: council_member
+glep_two:
+ name: glep2
+ description: glep 2
+ agenda: agenda_one
+ owner: council_member
diff --git a/spec/models/glep_spec.rb b/spec/models/glep_spec.rb
new file mode 100644
index 0000000..731ef03
--- /dev/null
+++ b/spec/models/glep_spec.rb
@@ -0,0 +1,25 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Glep do
+ before(:each) do
+ @glep = gleps(:glep_one)
+ end
+
+ [:guest, :developer, :council_member, :admin].each do |role|
+ it "should allow user with role #{role} to view" do
+ @glep.should be_viewable_by(users(role))
+ end
+ end
+
+ it "should allow developer to create" do
+ glep = Glep.new(
+ :name => 'glep_1',
+ :description => 'glep 1'
+ )
+ glep.should be_creatable_by(users(:developer))
+ end
+
+ it "should allow council member to update" do
+ @glep.should be_updatable_by(users(:council_member))
+ end
+end