Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added recipients and organizations and made the associations between …

…these and users all work
  • Loading branch information...
commit 174a612c203476fe77b624c56f5b45e135f9a0e2 1 parent 69850c4
@mikel authored
Showing with 979 additions and 19 deletions.
  1. +1 −0  app/controllers/email_templates_controller.rb
  2. +46 −0 app/controllers/organizations_controller.rb
  3. +54 −0 app/controllers/recipients_controller.rb
  4. +2 −0  app/helpers/organizations_helper.rb
  5. +2 −0  app/helpers/recipients_helper.rb
  6. +6 −0 app/models/organization.rb
  7. +20 −0 app/models/recipient.rb
  8. +9 −2 app/models/user.rb
  9. +3 −3 app/views/email_templates/index.html.erb
  10. +1 −1  app/views/home/index.html.erb
  11. +17 −0 app/views/layouts/application.html.erb
  12. +2 −0  app/views/organizations/_form.html.erb
  13. +3 −0  app/views/organizations/_organization.html.erb
  14. +5 −0 app/views/organizations/edit.html.erb
  15. +10 −0 app/views/organizations/index.html.erb
  16. +5 −0 app/views/organizations/new.html.erb
  17. +15 −0 app/views/recipients/_form.html.erb
  18. +4 −0 app/views/recipients/_recipient.html.erb
  19. +6 −0 app/views/recipients/edit.html.erb
  20. +6 −0 app/views/recipients/index.html.erb
  21. +5 −0 app/views/recipients/new.html.erb
  22. +3 −0  app/views/users/_form.html.erb
  23. +6 −0 app/views/users/_user.html.erb
  24. +2 −8 app/views/users/index.html.erb
  25. +6 −1 config/routes.rb
  26. +17 −0 db/migrate/20090519081741_create_recipients.rb
  27. +13 −0 db/migrate/20090519231831_create_organizations.rb
  28. +11 −0 db/migrate/20090520090847_add_organization_to_users_and_recipients.rb
  29. +9 −0 db/migrate/20090521234537_add_state_to_recipients.rb
  30. +20 −1 db/schema.rb
  31. +14 −0 features/manage_email_templates.feature
  32. +54 −0 features/manage_organizations.feature
  33. +79 −0 features/manage_recipients.feature
  34. +1 −0  features/manage_users.feature
  35. +11 −0 features/step_definitions/manage_organizations_steps.rb
  36. +19 −0 features/step_definitions/manage_recipients_steps.rb
  37. +2 −0  features/support/env.rb
  38. +22 −1 features/support/paths.rb
  39. +10 −0 spec/controllers/organizations_controller_spec.rb
  40. +10 −0 spec/controllers/recipients_controller_spec.rb
  41. +3 −0  spec/factories/organization_factory.rb
  42. +6 −0 spec/factories/recipient_factory.rb
  43. +1 −0  spec/factories/user_factory.rb
  44. +7 −0 spec/fixtures/organizations.yml
  45. +15 −0 spec/fixtures/recipients.yml
  46. +11 −0 spec/helpers/organizations_helper_spec.rb
  47. +11 −0 spec/helpers/recipients_helper_spec.rb
  48. +21 −0 spec/models/organization_spec.rb
  49. +48 −0 spec/models/recipient_spec.rb
  50. +39 −2 spec/models/user_spec.rb
  51. +286 −0 temp.html
View
1  app/controllers/email_templates_controller.rb
@@ -3,6 +3,7 @@ class EmailTemplatesController < ApplicationController
before_filter :require_user
def index
+ @email_templates = current_user.email_templates
end
def new
View
46 app/controllers/organizations_controller.rb
@@ -0,0 +1,46 @@
+class OrganizationsController < ApplicationController
+
+ before_filter :require_user
+ before_filter :admin_only
+
+ def index
+ @organizations = Organization.find(:all)
+ end
+
+ def new
+ @organization = Organization.new
+ end
+
+ def create
+ @organization = Organization.new(params[:organization])
+ if @organization.save
+ flash[:notice] = "Organization successfully created"
+ redirect_to organizations_path
+ else
+ render :action => :new
+ end
+ end
+
+ def edit
+ @organization = Organization.find(params[:id])
+ end
+
+ def update
+ @organization = Organization.find(params[:id])
+ @organization.attributes = params[:organization]
+ if @organization.save
+ flash[:notice] = "Organization successfully updated"
+ redirect_to organizations_path
+ else
+ render :action => :edit
+ end
+ end
+
+ def destroy
+ @organization = Organization.find(params[:id])
+ @organization.delete
+ flash[:notice] = "Organization successfully deleted"
+ redirect_to organizations_path
+ end
+
+end
View
54 app/controllers/recipients_controller.rb
@@ -0,0 +1,54 @@
+class RecipientsController < ApplicationController
+
+ before_filter :require_user
+
+ def index
+ @recipients = current_user.recipients
+ end
+
+ def new
+ @recipient = Recipient.new(:organization => current_user.organization)
+ end
+
+ def create
+ @recipient = Recipient.new(params[:recipient])
+ @recipient.organization = current_user.organization
+ if @recipient.save
+ flash[:notice] = "Recipient created"
+ redirect_to recipients_path
+ else
+ render :action => :new
+ end
+ end
+
+ def edit
+ @recipient = current_user.recipients.find(params[:id])
+ end
+
+ def update
+ @recipient = current_user.recipients.find(params[:id])
+ @recipient.attributes = params[:recipient]
+ @recipient.organization = current_user.organization
+ if @recipient.save
+ flash[:notice] = "Recipient updated"
+ redirect_to recipients_path
+ else
+ render :action => :new
+ end
+ end
+
+ def black_list
+ @recipient = current_user.recipients.find(params[:id])
+ @recipient.black_list!
+ flash[:notice] = "Recipient successfully black listed"
+ redirect_to recipients_path
+ end
+
+ def destroy
+ @recipient = current_user.recipients.find(params[:id])
+ @recipient.delete
+ flash[:notice] = "Recipient successfully deleted"
+ redirect_to recipients_path
+ end
+
+end
View
2  app/helpers/organizations_helper.rb
@@ -0,0 +1,2 @@
+module OrganizationsHelper
+end
View
2  app/helpers/recipients_helper.rb
@@ -0,0 +1,2 @@
+module RecipientsHelper
+end
View
6 app/models/organization.rb
@@ -0,0 +1,6 @@
+class Organization < ActiveRecord::Base
+
+ has_many :users
+ has_many :recipients
+
+end
View
20 app/models/recipient.rb
@@ -0,0 +1,20 @@
+class Recipient < ActiveRecord::Base
+
+ belongs_to :organization
+
+ validates_presence_of :organization_id
+ validates_associated :organization
+
+ def name
+ "#{given_name} #{family_name}"
+ end
+
+ def black_list!
+ self.update_attribute(:state, 'blacklisted')
+ end
+
+ def black_list
+ @black_list ||= (self.state == 'blacklisted')
+ end
+
+end
View
11 app/models/user.rb
@@ -3,11 +3,18 @@ class User < ActiveRecord::Base
has_many :email_templates
has_many :memberships
- has_many :roles, :through => :memberships
+ has_many :recipients, :through => :organization
+ has_many :roles, :through => :memberships
+
+ belongs_to :organization
- attr_accessible :given_name, :family_name, :email, :password, :password_confirmation
+ attr_accessible :given_name, :family_name, :email,
+ :password, :password_confirmation,
+ :organization_id
validate_on_update :check_last_admin?
+ validates_associated :organization
+ validates_presence_of :organization_id
def check_last_admin?
if @tried_to_remove_admin && last_admin?
View
6 app/views/email_templates/index.html.erb
@@ -1,4 +1,4 @@
<h2>Current Email Templates</h2>
-<%- current_user.email_templates.each do |email_template| -%>
- <%= render :partial => email_template %>
-<%- end -%>
+<%= link_to "Make a new email template", new_email_template_path %>
+<br />
+<%= render :partial => 'email_template', :collection => @email_templates %>
View
2  app/views/home/index.html.erb
@@ -9,7 +9,7 @@
<%= link_to "Make a new email template", new_email_template_path %>
<%- else -%>
<%- current_user.email_templates.each do |email_template| -%>
- <%= render :partial => "email_template" %>
+ <%= render :partial => "email_templates/email_template", :object => email_template %>
<%- end -%>
<%- end -%>
View
17 app/views/layouts/application.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="flashbox">
+ <%- flash.each do |name, msg| -%>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
+ </div>
+
+ <%= yield %>
+ </body>
+</html>
View
2  app/views/organizations/_form.html.erb
@@ -0,0 +1,2 @@
+<%= form.label :name %><br />
+<%= form.text_field :name %><br />
View
3  app/views/organizations/_organization.html.erb
@@ -0,0 +1,3 @@
+<%= organization.name %>
+ <%= link_to "Edit", edit_organization_path(organization) %>
+ <%= link_to "Delete", organization_path(organization), :method => :delete, :confirm => "Are you sure?", :id => "delete_#{organization.id}" %>
View
5 app/views/organizations/edit.html.erb
@@ -0,0 +1,5 @@
+<% form_for @organization do |f| %>
+ <%= f.error_messages %>
+ <%= render :partial => "form", :object => f %>
+ <%= f.submit "Update" %>
+<% end %>
View
10 app/views/organizations/index.html.erb
@@ -0,0 +1,10 @@
+<%- if flash -%>
+ <p><%= flash[:notice] -%>
+ <%= flash[:error] -%></p>
+<%- end -%>
+
+<%= render :partial => 'organization', :collection => @organizations %>
+
+<p>
+ <%= link_to "New Organization", new_organization_path %>
+</p>
View
5 app/views/organizations/new.html.erb
@@ -0,0 +1,5 @@
+<% form_for @organization do |f| %>
+ <%= f.error_messages %>
+ <%= render :partial => "form", :object => f %>
+ <%= f.submit "Create" %>
+<% end %>
View
15 app/views/recipients/_form.html.erb
@@ -0,0 +1,15 @@
+<%= form.label :given_name %><br />
+<%= form.text_field :given_name %><br />
+<br />
+<%= form.label :family_name %><br />
+<%= form.text_field :family_name %><br />
+<br />
+<%= form.label :email %><br />
+<%= form.text_field :email %><br />
+<br />
+<%= form.label :black_listed %><br />
+<%= form.check_box :black_listed %><br />
+<br />
+<%= form.label :undeliverable_count %><br />
+<%= select("recipient", :undeliverable_count, ((0..5).map { |i| [i,i] })) %><br />
+<br />
View
4 app/views/recipients/_recipient.html.erb
@@ -0,0 +1,4 @@
+<%= recipient.name %>
+ <%= link_to "Edit", edit_recipient_path(recipient) %>
+ <%= link_to "Black List", black_list_recipient_path(recipient), :method => :delete, :confirm => "Are you sure you want to black list this recipient?", :id => "black_list_#{recipient.id}" %>
+ <%= link_to "Delete", recipient_path(recipient), :method => :delete, :confirm => "Deleting is primarily for invalid records, are you sure?", :id => "delete_#{recipient.id}" %>
View
6 app/views/recipients/edit.html.erb
@@ -0,0 +1,6 @@
+<h2>Editing <%= @recipient.name %></h2>
+<% form_for @recipient do |f| %>
+ <%= f.error_messages %>
+ <%= render :partial => "form", :object => f %>
+ <%= f.submit "Update" %>
+<% end %>
View
6 app/views/recipients/index.html.erb
@@ -0,0 +1,6 @@
+<h2>Current Recipients</h2>
+<%= link_to "Add a recipient", new_recipient_path %>
+<br />
+
+<%= render :partial => 'recipient', :collection => @recipients %>
+
View
5 app/views/recipients/new.html.erb
@@ -0,0 +1,5 @@
+<% form_for @recipient do |f| %>
+ <%= f.error_messages %>
+ <%= render :partial => "form", :object => f %>
+ <%= f.submit "Create" %>
+<% end %>
View
3  app/views/users/_form.html.erb
@@ -16,6 +16,9 @@
<%= form.label :family_name %><br />
<%= form.text_field :family_name %><br />
<br />
+<%= form.label :organization %><br />
+<%= form.collection_select :organization_id, Organization.all(:order => 'name'), :id, :name, :include_blank => 'Please select Organization' %><br />
+<br />
<%- if current_user.admin -%>
<%= form.label :admin %><br />
<%= form.check_box :admin %><br />
View
6 app/views/users/_user.html.erb
@@ -0,0 +1,6 @@
+ <%= user.given_name %>
+ <%= user.family_name %>
+ <%= user.email %>
+ <%= user.login %>
+ <%= link_to "Edit", edit_user_path(user) %>
+ <%= link_to "Delete", user_path(user), :method => :delete, :confirm => "Are you sure?", :id => "delete_#{user.id}" %>
View
10 app/views/users/index.html.erb
@@ -2,14 +2,8 @@
<p><%= flash[:notice] -%>
<%= flash[:error] -%></p>
<%- end -%>
-<%- @users.each do |user| -%>
-<%= user.given_name %>
-<%= user.family_name %>
-<%= user.email %>
-<%= user.login %>
- <%= link_to "Edit", edit_user_path(user) %>
- <%= link_to "Delete", user_path(user), :method => :delete, :confirm => "Are you sure?", :id => "delete_#{user.id}" %>
-<%- end -%>
+
+<%= render :partial => 'user', :collection => @users %>
<p>
<%= link_to "New User", new_user_path %>
View
7 config/routes.rb
@@ -40,6 +40,11 @@
map.login '/login', :controller => 'user_sessions', :action => 'new', :method => 'get'
map.logout '/logout', :controller => 'user_sessions', :action => 'destroy', :method => 'delete'
- map.resources :users, :user_sessions, :email_templates
+ map.resources :users,
+ :user_sessions,
+ :email_templates,
+ :organizations
+
+ map.resources :recipients, { :member => 'black_list', :method => 'delete' }
end
View
17 db/migrate/20090519081741_create_recipients.rb
@@ -0,0 +1,17 @@
+class CreateRecipients < ActiveRecord::Migration
+ def self.up
+ create_table :recipients do |t|
+ t.string :given_name
+ t.string :family_name
+ t.string :email
+ t.integer :undeliverable_count, :default => 0
+ t.boolean :black_listed, :default => false
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :recipients
+ end
+end
View
13 db/migrate/20090519231831_create_organizations.rb
@@ -0,0 +1,13 @@
+class CreateOrganizations < ActiveRecord::Migration
+ def self.up
+ create_table :organizations do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :organizations
+ end
+end
View
11 db/migrate/20090520090847_add_organization_to_users_and_recipients.rb
@@ -0,0 +1,11 @@
+class AddOrganizationToUsersAndRecipients < ActiveRecord::Migration
+ def self.up
+ add_column :users, :organization_id, :integer
+ add_column :recipients, :organization_id, :integer
+ end
+
+ def self.down
+ remove_column :recipients, :organization_id
+ remove_column :users, :organization_id
+ end
+end
View
9 db/migrate/20090521234537_add_state_to_recipients.rb
@@ -0,0 +1,9 @@
+class AddStateToRecipients < ActiveRecord::Migration
+ def self.up
+ add_column :recipients, :state, :string, :limit => 10
+ end
+
+ def self.down
+ remove_column :recipients, :state
+ end
+end
View
21 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090518111443) do
+ActiveRecord::Schema.define(:version => 20090521234537) do
create_table "email_templates", :force => true do |t|
t.string "title"
@@ -26,6 +26,24 @@
t.datetime "updated_at"
end
+ create_table "organizations", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "recipients", :force => true do |t|
+ t.string "given_name"
+ t.string "family_name"
+ t.string "email"
+ t.integer "undeliverable_count", :default => 0
+ t.boolean "black_listed", :default => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "organization_id"
+ t.string "state", :limit => 10
+ end
+
create_table "roles", :force => true do |t|
t.string "name"
t.datetime "created_at"
@@ -51,6 +69,7 @@
t.string "last_login_ip"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "organization_id"
end
end
View
14 features/manage_email_templates.feature
@@ -14,12 +14,26 @@ Feature: Manage Email Templates
Then I should see "No email templates defined"
And I should see "Make a new email template"
+ Scenario: One template in the system
+ Given I am logged in
+ And there is an email template I made in the system with title "Hello There"
+ And there is an email template I made in the system with title "Going away"
+ When I go to the homepage
+ Then I should see "Hello There"
+ And I should see "Going away"
+
Scenario: Making a new email template
Given I am logged in
When I go to the homepage
And I follow "Make a new email template"
Then I should be on the new email templates page
+ Scenario: Making a new email template
+ Given I am logged in
+ When I go to the email templates page
+ And I follow "Make a new email template"
+ Then I should be on the new email templates page
+
Scenario: Saving a new email template
Given I am logged in
When I go to the new email templates page
View
54 features/manage_organizations.feature
@@ -0,0 +1,54 @@
+Feature: Manage Organizations
+ In order to be able to track users by organizations
+ As an administrator
+ I want to be able to manage organizations
+
+ Scenario: Not being logged in and trying to access organization management
+ Given I am logged out
+ When I go to the organizations page
+ Then I should be on the login page
+
+ Scenario: Not being logged in and trying to access organization management
+ Given I am logged in
+ When I go to the organizations page
+ Then I should be on the homepage
+ And I should see "You must be an administrator to access this page"
+
+ Scenario: One organization in the system
+ Given I am logged in as an admin
+ And there is a organization I added in the system called "Sydney"
+ When I go to the organizations page
+ Then I should see "Sydney"
+ And I should see "Edit"
+ And I should see "Delete"
+
+ Scenario: Going to the new organization page
+ Given I am logged in as an admin
+ When I go to the organizations page
+ And I follow "New Organization"
+ Then I should be on the new organization page
+
+ Scenario: Adding a new organization
+ Given I am logged in as an admin
+ And I am on the new organization page
+ When I fill in "Name" with "Sydney"
+ And I press "Create"
+ Then I should be on the organizations page
+ And I should see "Sydney"
+
+ Scenario: Editing an organization
+ Given I am logged in as an admin
+ And there is a organization I added in the system called "Sydney"
+ And I am on the organizations page
+ When I follow "Edit"
+ Then I should be on the edit page for organization "Sydney"
+
+ Scenario: Deleting an organization
+ Given I am logged in as an admin
+ And no organizations in the system
+ And there is a organization I added in the system called "Sydney"
+ And I am on the organizations page
+ When I follow "Delete"
+ Then I should be on the organizations page
+ And I should see "Organization successfully deleted"
+ And there should be 0 organizations in the system
View
79 features/manage_recipients.feature
@@ -0,0 +1,79 @@
+Feature: Manage Recipients
+ In order to be able to send an email to our public
+ As a user
+ I want to be able to manage recipients
+
+ Scenario: Not being logged in and trying to access recipients
+ Given I am logged out
+ When I go to the recipients page
+ Then I should be on the login page
+
+ Scenario: No recipients in the system
+ Given I am logged in
+ When I go to the recipients page
+ Then I should see "Add a recipient"
+ And I should not see "Edit"
+ And I should not see "Delete"
+
+ Scenario: One recipient in the system
+ Given I am logged in
+ And there is a recipient I added in the system called "Mikel Lindsaar"
+ When I go to the recipients page
+ Then I should see "Mikel Lindsaar"
+ And I should see "Edit"
+ And I should see "Delete"
+
+ Scenario: Going to the new recipient page
+ Given I am logged in
+ When I go to the recipients page
+ And I follow "Add a recipient"
+ Then I should be on the new recipient page
+
+ Scenario: Adding a new recipient
+ Given I am logged in
+ And I am on the new recipient page
+ When I fill in "Given Name" with "Mikel"
+ And I fill in "Family Name" with "Lindsaar"
+ And I press "Create"
+ Then I should be on the recipients page
+ And I should see "Mikel Lindsaar"
+
+ Scenario: Editing a recipient
+ Given I am logged in
+ And there is a recipient I added in the system called "Mikel Lindsaar"
+ And I am on the recipients page
+ When I follow "Edit"
+ Then I should be on the edit page for recipient "Mikel Lindsaar"
+ And I should see "Editing Mikel Lindsaar"
+
+ Scenario: Updating a recipient
+ Given I am logged in
+ And there is a recipient I added in the system called "Mikel Lindsaar"
+ And I am on the recipients page
+ When I follow "Edit"
+ And I fill in "Given Name" with "Billy"
+ And I fill in "Family Name" with "Joel"
+ And I press "Update"
+ Then I should be on the recipients page
+ And I should see "Billy Joel"
+
+ Scenario: Black Listing a recipient
+ Given I am logged in
+ And no recipients in the system
+ And there is a recipient I added in the system called "Mikel Lindsaar"
+ And I am on the recipients page
+ When I follow "Black List"
+ Then I should be on the recipients page
+ And I should see "Recipient successfully black listed"
+ And there should be 1 recipient in the system
+ And "Mikel Lindsaar" should be black listed
+
+ Scenario: Deleting a recipient
+ Given I am logged in
+ And no recipients in the system
+ And there is a recipient I added in the system called "Mikel Lindsaar"
+ And I am on the recipients page
+ When I follow "Delete"
+ Then I should be on the recipients page
+ And I should see "Recipient successfully deleted"
+ And there should be 0 recipients in the system
View
1  features/manage_users.feature
@@ -36,6 +36,7 @@ Feature: Managing users
And I fill in "email" with "mikel@me.com"
And I fill in "password" with "1234abcd"
And I fill in "password confirmation" with "1234abcd"
+ And I select "Sydney" from "user_organization_id"
And I press "Create"
Then I should be on the users page
And I should see "User mlindsaar successfully created"
View
11 features/step_definitions/manage_organizations_steps.rb
@@ -0,0 +1,11 @@
+Given /^there is a organization I added in the system called "([^\"]*)"$/ do |name|
+ Factory(:organization, :name => name)
+end
+
+Then /^no organizations in the system$/ do
+ Organization.destroy_all
+end
+
+Then /^there should be (\d+) organizations in the system$/ do |number|
+ Organization.count.should == number.to_i
+end
View
19 features/step_definitions/manage_recipients_steps.rb
@@ -0,0 +1,19 @@
+Given /^there is a recipient I added in the system called "([^\"]*)"$/ do |name|
+ org = Organization.find(:first)
+ given, family = name.split
+ Factory(:recipient, :given_name => given, :family_name => family, :organization => org)
+end
+
+Given /^no recipients in the system$/ do
+ Recipient.destroy_all
+end
+
+Then /^there should be (\d+) recipients? in the system$/ do |number|
+ Recipient.count.should == number.to_i
+end
+
+Then /^"([^\"]*)" should be black listed$/ do |name|
+ given, family = name.split
+ recipient = Recipient.find_by_given_name_and_family_name(given, family)
+ recipient.black_list.should be_true
+end
View
2  features/support/env.rb
@@ -13,6 +13,8 @@
config.mode = :rails
end
+require 'ruby-debug'
+
require 'cucumber/rails/rspec'
require 'webrat/core/matchers'
require "authlogic/test_case"
View
23 features/support/paths.rb
@@ -26,7 +26,7 @@ def path_to(page_name)
when /the new user page/
new_user_path
- when /the edit user page for "(\w+)"/
+ when /the edit user page for "([^\"]*)"/
user = User.find_by_login($1)
edit_user_path(user.id)
@@ -45,6 +45,27 @@ def path_to(page_name)
when /edit the first email template/
edit_email_template_path(EmailTemplate.find(:first))
+ when /the recipients page/
+ recipients_path
+
+ when /the new recipient page/
+ new_recipient_path
+
+ when /edit page for recipient "([^\"]*)"$/
+ first, last = $1.split
+ recipient = Recipient.find_by_given_name_and_family_name(first, last)
+ edit_recipient_path(recipient)
+
+ when /the organizations page/
+ organizations_path
+
+ when /the new organization page/
+ new_organization_path
+
+ when /the edit page for organization "([^\"]*)"$/
+ org = Organization.find_by_name($1)
+ edit_organization_path(org)
+
# Add more page name => path mappings here
else
View
10 spec/controllers/organizations_controller_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe OrganizationsController do
+
+ #Delete this example and add some real ones
+ it "should use OrganizationsController" do
+ controller.should be_an_instance_of(OrganizationsController)
+ end
+
+end
View
10 spec/controllers/recipients_controller_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe RecipientsController do
+
+ #Delete this example and add some real ones
+ it "should use RecipientsController" do
+ controller.should be_an_instance_of(RecipientsController)
+ end
+
+end
View
3  spec/factories/organization_factory.rb
@@ -0,0 +1,3 @@
+Factory.define :organization do |o|
+ o.name 'organization'
+end
View
6 spec/factories/recipient_factory.rb
@@ -0,0 +1,6 @@
+Factory.define :recipient do |r|
+ r.given_name 'George'
+ r.family_name 'Man'
+ r.email 'george@email.com'
+ r.association :organization, :name => 'Sydney'
+end
View
1  spec/factories/user_factory.rb
@@ -5,6 +5,7 @@
u.password "PassWord"
u.password_confirmation { |a| a.password }
u.email { |a| "#{a.login}@someplace.com" }
+ u.association :organization, :name => 'Sydney'
end
Factory.define :admin_user, :parent => :user do |a|
View
7 spec/fixtures/organizations.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
View
15 spec/fixtures/recipients.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ given_name: MyString
+ family_name: MyString
+ email: MyString
+ undeliverable_count: 1
+ black_listed: false
+
+two:
+ given_name: MyString
+ family_name: MyString
+ email: MyString
+ undeliverable_count: 1
+ black_listed: false
View
11 spec/helpers/organizations_helper_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe OrganizationsHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should be included in the object returned by #helper" do
+ included_modules = (class << helper; self; end).send :included_modules
+ included_modules.should include(OrganizationsHelper)
+ end
+
+end
View
11 spec/helpers/recipients_helper_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe RecipientsHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should be included in the object returned by #helper" do
+ included_modules = (class << helper; self; end).send :included_modules
+ included_modules.should include(RecipientsHelper)
+ end
+
+end
View
21 spec/models/organization_spec.rb
@@ -0,0 +1,21 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Organization do
+
+ describe "user association" do
+ it "should have many users" do
+ organization = Factory(:organization)
+ user = Factory(:user, :organization => organization)
+ organization.users.should include(user)
+ end
+ end
+
+ describe "recipient association" do
+ it "should have many recipients" do
+ organization = Factory(:organization)
+ recipient = Factory(:recipient, :organization => organization)
+ organization.recipients.should include(recipient)
+ end
+ end
+
+end
View
48 spec/models/recipient_spec.rb
@@ -0,0 +1,48 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Recipient do
+
+ describe "black listing" do
+ it "should allow itself to black listed" do
+ recipient = Factory(:recipient)
+ doing { recipient.black_list! }.should_not raise_error
+ end
+
+ it "should say it is black listed" do
+ recipient = Factory(:recipient)
+ recipient.black_list!
+ recipient.black_list.should be_true
+ end
+ end
+
+ describe "organization association" do
+ it "should belong to an organization" do
+ recipient = Factory(:recipient)
+ organization = Factory(:organization)
+ doing { recipient.organization = organization }.should_not raise_error
+ end
+
+ it "should have an organization" do
+ recipient = Factory(:recipient)
+ organization = Factory(:organization)
+ recipient.organization = organization
+ recipient.organization.should == organization
+ end
+
+ it "should be invalid without an organization" do
+ recipient = Factory(:recipient)
+ recipient.organization = nil
+ recipient.should_not be_valid
+ end
+ end
+
+ describe "helper methods" do
+ it "should give the name as the given and family names" do
+ recipient = Factory(:recipient)
+ recipient.given_name = 'Mikel'
+ recipient.family_name = 'Lindsaar'
+ recipient.name.should == 'Mikel Lindsaar'
+ end
+ end
+
+end
View
41 spec/models/user_spec.rb
@@ -141,8 +141,45 @@
describe "template association" do
it "should have many templates" do
user = Factory(:user)
- template = Factory(:email_template)
- doing { user.email_templates << template }.should_not raise_error
+ email_template = Factory(:email_template)
+ doing { user.email_templates << email_template }.should_not raise_error
+ end
+
+ it "should have an templates" do
+ user = Factory(:user)
+ email_template = Factory(:email_template)
+ user.email_templates << email_template
+ user.email_templates.should include(email_template)
+ end
+ end
+
+ describe "organization association" do
+ it "should belong to an organization" do
+ user = Factory(:user)
+ organization = Factory(:organization)
+ doing { user.organization = organization }.should_not raise_error
+ end
+
+ it "should have an organization" do
+ user = Factory(:user)
+ organization = Factory(:organization)
+ user.organization = organization
+ user.organization.should == organization
+ end
+
+ it "should be invalid without an organization" do
+ user = Factory(:user)
+ user.organization = nil
+ user.should_not be_valid
+ end
+ end
+
+ describe "recipients association through organizations" do
+ it "should have a proxy association to recipients that references the organziation" do
+ organization = Factory(:organization)
+ user = Factory(:user, :organization => organization)
+ recipient = Factory(:recipient, :organization => organization)
+ user.recipients.should include(recipient)
end
end
View
286 temp.html
@@ -0,0 +1,286 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Cucumber</title>
+ <style type="text/css">
+
+
+
+
+
+.cucumber {
+ background: black;
+ color: white;
+ padding: 1em;
+}
+.cucumber .passed {
+ color: green;
+}
+.cucumber .undefined {
+ color: yellow;
+}
+.cucumber .pending {
+ color: yellow;
+}
+.cucumber .failed {
+ color: red;
+}
+.cucumber .skipped {
+ color: cyan;
+}
+.cucumber .outline {
+ color: cyan;
+}
+.cucumber .param {
+ font-weight: bold;
+}
+.cucumber a {
+ text-decoration: none;
+ color: inherit;
+}
+.cucumber a:hover {
+ text-decoration: underline;
+}
+.cucumber a:visited {
+ font-weight: normal;
+}
+.cucumber ol {
+ list-style: none;
+}
+.cucumber .stats {
+ margin: 2em;
+}
+.cucumber .summary ul.features li {
+ display: inline;
+}
+.cucumber .backtrace {
+ margin-top: 0;
+ margin-bottom: 0;
+ margin-left: 1em;
+}
+ </style>
+ </head>
+ <body>
+ <div class="cucumber">
+ <div class="feature">
+ <h2>Feature: Manage Recipients</h2>
+ <p>
+In order to be able to send an email to our public <br/>
+As a user <br/>
+I want to be able to manage recipients <br/>
+ </p>
+ <div class="scenario">
+ <h3>Scenario: Not being logged in and trying to access recipients</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_7">
+ <div>
+Given I am logged out </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_8">
+ <div>
+When I go to &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_9">
+ <div>
+Then I should be on &lt;span&gt;the login page&lt;/span&gt; </div>
+ </li>
+ </ol>
+ </div>
+ <div class="scenario">
+ <h3>Scenario: No recipients in the system</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_12">
+ <div>
+Given I am logged in </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_13">
+ <div>
+When I go to &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_14">
+ <div>
+Then I should see &quot;&lt;span&gt;Add a recipient&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_15">
+ <div>
+And I should not see &quot;&lt;span&gt;Edit&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_16">
+ <div>
+And I should not see &quot;&lt;span&gt;Delete&lt;/span&gt;&quot; </div>
+ </li>
+ </ol>
+ </div>
+ <div class="scenario">
+ <h3>Scenario: One recipient in the system</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_19">
+ <div>
+Given I am logged in </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_20">
+ <div>
+And there is a recipient I added in the system called &quot;&lt;span&gt;Mikel Lindsaar&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_21">
+ <div>
+When I go to &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="failed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_22">
+ <div>
+Then I should see &quot;&lt;span&gt;Mikel Lindsaar&lt;/span&gt;&quot; </div>
+ <pre class="failed">expected the following element's content to include &quot;Mikel Lindsaar&quot;:
+Current RecipientsAdd a recipient (Spec::Expectations::ExpectationNotMetError)
+/Users/mikel/Rails/mailer/features/step_definitions/webrat_steps.rb:94:in `/^I should see &quot;([^\&quot;]*)&quot;$/'
+/Users/mikel/Rails/mailer/features/manage_recipients.feature:22:in `Then I should see &quot;Mikel Lindsaar&quot;'</pre>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_23">
+ <div>
+And I should see &quot;&lt;span&gt;Edit&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_24">
+ <div>
+And I should see &quot;&lt;span&gt;Delete&lt;/span&gt;&quot; </div>
+ </li>
+ </ol>
+ </div>
+ <div class="scenario">
+ <h3>Scenario: Going to the new recipient page</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_27">
+ <div>
+Given I am logged in </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_28">
+ <div>
+When I go to &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="failed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_29">
+ <div>
+And I follow &quot;&lt;span&gt;Add a recipient&lt;/span&gt;&quot; </div>
+ <pre class="failed">No action responded to new. Actions: index (ActionController::UnknownAction)
+(eval):2:in `click_link'
+/Users/mikel/Rails/mailer/features/step_definitions/webrat_steps.rb:19:in `/^I follow &quot;([^\&quot;]*)&quot;$/'
+/Users/mikel/Rails/mailer/features/manage_recipients.feature:29:in `And I follow &quot;Add a recipient&quot;'</pre>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_30">
+ <div>
+Then I should be on &lt;span&gt;the new recipient page&lt;/span&gt; </div>
+ </li>
+ </ol>
+ </div>
+ <div class="scenario">
+ <h3>Scenario: Adding a new recipient</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_33">
+ <div>
+Given I am logged in </div>
+ </li>
+ <li class="failed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_34">
+ <div>
+And I am on &lt;span&gt;the new recipient page&lt;/span&gt; </div>
+ <pre class="failed">No action responded to new. Actions: index (ActionController::UnknownAction)
+(eval):2:in `visit'
+/Users/mikel/Rails/mailer/features/step_definitions/webrat_steps.rb:7:in `/^I am on (.+)$/'
+/Users/mikel/Rails/mailer/features/manage_recipients.feature:34:in `And I am on the new recipient page'</pre>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_35">
+ <div>
+When I fill in &quot;&lt;span&gt;Given Name&lt;/span&gt;&quot; with &quot;&lt;span&gt;Mikel&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_36">
+ <div>
+And I fill in &quot;&lt;span&gt;Family Name&lt;/span&gt;&quot; with &quot;&lt;span&gt;Lindsaar&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_37">
+ <div>
+And I press &quot;&lt;span&gt;Create&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_38">
+ <div>
+Then I should be on &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_39">
+ <div>
+And I should see &quot;&lt;span&gt;Mikel Lindsaar&lt;/span&gt;&quot; </div>
+ </li>
+ </ol>
+ </div>
+ <div class="scenario">
+ <h3>Scenario: Editing a recipient</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_42">
+ <div>
+Given I am logged in </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_43">
+ <div>
+And there is a recipient I added in the system called &quot;&lt;span&gt;Mikel Lindsaar&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_44">
+ <div>
+And I am on &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="failed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_45">
+ <div>
+When I follow &quot;&lt;span&gt;Edit&lt;/span&gt;&quot; </div>
+ <pre class="failed">Could not find link with text or title or id &quot;Edit&quot; (Webrat::NotFoundError)
+(eval):2:in `click_link'
+/Users/mikel/Rails/mailer/features/step_definitions/webrat_steps.rb:19:in `/^I follow &quot;([^\&quot;]*)&quot;$/'
+/Users/mikel/Rails/mailer/features/manage_recipients.feature:45:in `When I follow &quot;Edit&quot;'</pre>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_46">
+ <div>
+Then I should be on &lt;span&gt;the edit page for recipient &quot;Mikel Lindsaar&quot;&lt;/span&gt; </div>
+ </li>
+ </ol>
+ </div>
+ <div class="scenario">
+ <h3>Scenario: Deleting a recipient</h3>
+ <ol>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_49">
+ <div>
+Given I am logged in </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_50">
+ <div>
+And no recipients in the system </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_51">
+ <div>
+And there is a recipient I added in the system called &quot;&lt;span&gt;Mikel Lindsaar&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="passed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_52">
+ <div>
+And I am on &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="failed" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_53">
+ <div>
+When I follow &quot;&lt;span&gt;Black List&lt;/span&gt;&quot; </div>
+ <pre class="failed">Could not find link with text or title or id &quot;Black List&quot; (Webrat::NotFoundError)
+(eval):2:in `click_link'
+/Users/mikel/Rails/mailer/features/step_definitions/webrat_steps.rb:19:in `/^I follow &quot;([^\&quot;]*)&quot;$/'
+/Users/mikel/Rails/mailer/features/manage_recipients.feature:53:in `When I follow &quot;Black List&quot;'</pre>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_54">
+ <div>
+Then I should be on &lt;span&gt;the recipients page&lt;/span&gt; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_55">
+ <div>
+And I should see &quot;&lt;span&gt;Recipient successfully black listed&lt;/span&gt;&quot; </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_56">
+ <div>
+And there should be &lt;span&gt;1&lt;/span&gt; recipient in the system </div>
+ </li>
+ <li class="skipped" id="_Users_mikel_Rails_mailer_features_manage_recipients_feature_57">
+ <div>
+And &quot;&lt;span&gt;Mikel Lindsaar&lt;/span&gt;&quot; should be black listed </div>
+ </li>
+ </ol>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.