Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Got adding and deleting of recipients from messages working correctly…

…. All specs and features passing.
  • Loading branch information...
commit e89b8be3e8b02516f8c93a734b78ac2ec3a1044b 1 parent 5f012e0
@mikel authored
View
14 app/controllers/recipients_controller.rb
@@ -43,12 +43,18 @@ def 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
+ if params[:message_id]
+ @message = Message.find(params[:message_id])
+ @message.recipients.delete(@recipient)
+ redirect_to edit_message_path(@message)
+ else
+ @recipient.delete
+ flash[:notice] = "Recipient successfully deleted"
+ redirect_to recipients_path
+ end
end
end
View
4 app/models/message.rb
@@ -37,6 +37,10 @@ def after_save
update_template if changes.include?('email_template') || changes.include?('email_template_id')
end
+ def organization
+ user.organization
+ end
+
def update_template
self.attributes = email_template.copy_attributes
email_template.attachments.each do |attachment|
View
4 features/messages_wizard.feature
@@ -222,7 +222,7 @@ Feature: Messages Wizard
When I go to the edit page for "Message" with a "title" of "My Email"
And I follow "Remove"
Then I should see "Select Recipients"
- And the message called "My email" should have no recipients
+ And the message called "My Email" should have no recipients
Scenario: Removing a group from a created message
Given I am logged in
@@ -231,5 +231,5 @@ Feature: Messages Wizard
When I go to the edit page for "Message" with a "title" of "My Email"
And I follow "Remove"
Then I should see "Select Recipients"
- And the message called "My email" should have no groups
+ And the message called "My Email" should have no groups
View
24 features/step_definitions/manage_messages.rb
@@ -1,35 +1,27 @@
When /^there is a message called "([^\"]*)" in the system with "([^\"]*)" as a recipient$/ do |title, recipient|
- message = Factory(:message, :title => title, :state => 'content_edited')
+ message = Factory(:message, :title => title, :state => 'content_edited', :user => User.first)
given, family = recipient.split(" ", 2)
- recipient = Factory(:recipient, :given_name => given, :family_name => family)
+ recipient = Factory(:recipient, :given_name => given, :family_name => family, :organization => User.first.organization)
message.save!
message.recipients << recipient
end
When /^there is a message called "([^\"]*)" in the system with "([^\"]*)" as a group$/ do |title, group|
- message = Factory(:message, :title => title, :state => 'content_edited')
+ message = Factory(:message, :title => title, :state => 'content_edited', :user => User.first)
group = Factory(:group, :name => group, :user => User.find(:first))
message.save!
message.groups << group
end
When /^there is a message called "([^\"]*)" in the system$/ do |title|
- message = Factory(:message, :title => title, :state => 'content_edited')
+ message = Factory(:message, :title => title, :state => 'content_edited', :user => User.first)
message.save!
end
-Then /^the message entitled "([^\"]*)" should have one recipient/ do |title|
- Message.find_by_title(title).recipients.count.should == 1
+Then /^the message entitled "([^\"]*)" should have one (.*)$/ do |title, collection|
+ Message.find(:first, :conditions => {:title => title}).send(collection.pluralize).count.should == 1
end
-Then /^the message entitled "([^\"]*)" should have one group/ do |title|
- Message.find_by_title(title).groups.count.should == 1
+Then /^the message called "([^\"]*)" should have no (.*)$/ do |title, collection|
+ Message.find(:first, :conditions => {:title => title}).send(collection).count.should == 0
end
-
-Then /^the message called "([^\"]*)" should have no recipients$/ do |title|
- Message.find_by_title(title).recipients.count.should == 0
-end
-
-Then /^the message called "([^\"]*)" should have no groups$/ do |title|
- Group.find_by_title(title).groups.count.should == 0
-end
View
4 spec/factories/message_factory.rb
@@ -2,13 +2,13 @@
m.title "Hello World"
m.source "edit"
m.multipart false
- m.user User.first
+ m.association :user
m.html_part "<h1>Hello World</h1>"
m.plain_part "Hello World"
end
Factory.define :multipart_message, :parent => :message do |m|
m.multipart true
- m.user User.first
+ m.association :user
end
View
2  spec/factories/organization_factory.rb
@@ -1,3 +1,3 @@
Factory.define :organization do |o|
- o.name 'organization'
+ o.name 'Sydney'
end
View
2  spec/factories/recipient_factory.rb
@@ -2,5 +2,5 @@
r.given_name 'George'
r.family_name 'Man'
r.email 'george@email.com'
- r.association :organization, :name => 'Sydney'
+ r.association :organization
end
View
2  spec/factories/user_factory.rb
@@ -5,7 +5,7 @@
u.password "PassWord"
u.password_confirmation { |a| a.password }
u.email { |a| "#{a.login}@someplace.com" }
- u.association :organization, :name => 'Sydney'
+ u.association :organization
end
Factory.define :admin_user, :parent => :user do |a|
View
6 spec/models/message_spec.rb
@@ -74,6 +74,12 @@
@message.groups.should include(@group)
end
+ it "should have an organization via user" do
+ @org = Factory(:organization)
+ @user = Factory(:user, :organization => @org)
+ @message = Message.new(:user => @user)
+ @message.organization.should == @org
+ end
end
describe "helper for adding a group individually" do
Please sign in to comment.
Something went wrong with that request. Please try again.