saucy 0.2.39 → 0.2.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ class InvitationsController < ApplicationController
12
12
  def create
13
13
  @invitation = Invitation.new(params[:invitation])
14
14
  @invitation.account = current_account
15
+ @invitation.sender = current_user
15
16
  if @invitation.save
16
17
  flash[:success] = "User invited."
17
18
  redirect_to account_memberships_url(current_account)
@@ -4,8 +4,15 @@ class InvitationMailer < ActionMailer::Base
4
4
  subject = I18n.t(:subject,
5
5
  :scope => [:saucy, :mailers, :invitation_mailer, :invititation],
6
6
  :default => "Invitation")
7
- mail :to => invitation.email,
8
- :subject => subject,
9
- :from => Saucy::Configuration.mailer_sender
7
+ mail :to => invitation.email,
8
+ :subject => subject,
9
+ :reply_to => invitation.sender_email,
10
+ :from => sender_name_and_support_address
11
+ end
12
+
13
+ private
14
+
15
+ def sender_name_and_support_address
16
+ %{"#{@invitation.sender_name}" <#{Saucy::Configuration.mailer_sender}>}
10
17
  end
11
18
  end
@@ -1,5 +1,6 @@
1
1
  class Invitation < ActiveRecord::Base
2
2
  belongs_to :account
3
+ belongs_to :sender, :class_name => 'User'
3
4
  validates_presence_of :account_id
4
5
  validates_presence_of :email
5
6
  has_and_belongs_to_many :projects
@@ -46,6 +47,14 @@ class Invitation < ActiveRecord::Base
46
47
  code
47
48
  end
48
49
 
50
+ def sender_name
51
+ sender.name
52
+ end
53
+
54
+ def sender_email
55
+ sender.email
56
+ end
57
+
49
58
  private
50
59
 
51
60
  def deliver_invitation
@@ -48,6 +48,7 @@ end
48
48
  Factory.define :invitation do |f|
49
49
  f.email { Factory.next(:email) }
50
50
  f.association :account
51
+ f.association :sender, :factory => :user
51
52
  end
52
53
 
53
54
  Factory.define :plan do |f|
@@ -34,6 +34,7 @@ class CreateSaucyTables < ActiveRecord::Migration
34
34
  create_table :invitations do |table|
35
35
  table.string :email
36
36
  table.integer :account_id
37
+ table.integer :sender_id
37
38
  table.boolean :admin, :null => false, :default => false
38
39
  table.string :code
39
40
  table.boolean :used, :default => false, :null => false
@@ -55,6 +55,7 @@ describe InvitationsController, "valid create", :as => :account_admin do
55
55
  before do
56
56
  Invitation.stubs(:new => invitation)
57
57
  invitation.stubs(:account=)
58
+ invitation.stubs(:sender=)
58
59
  invitation.stubs(:save => true)
59
60
  post :create, :account_id => account.to_param, :invitation => attributes
60
61
  end
@@ -66,6 +67,7 @@ describe InvitationsController, "valid create", :as => :account_admin do
66
67
  it "saves an invitation" do
67
68
  Invitation.should have_received(:new).with(attributes)
68
69
  invitation.should have_received(:account=).with(account)
70
+ invitation.should have_received(:sender=).with(current_user)
69
71
  invitation.should have_received(:save)
70
72
  end
71
73
 
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe InvitationMailer, "invitation" do
4
+ let(:invitation) { Factory(:invitation) }
5
+ subject { InvitationMailer.invitation(invitation) }
6
+
7
+ it "sets reply-to to the user that sent the invitation" do
8
+ subject.reply_to.should == [invitation.sender_email]
9
+ end
10
+
11
+ it "sets from to the user's name" do
12
+ from = subject.header_fields.detect { |field| field.name == "From"}
13
+ from.value.should =~ %r{^"#{invitation.sender_name}" <.*>$}
14
+ end
15
+
16
+ it "sends from the support address" do
17
+ subject.from.should == [Saucy::Configuration.mailer_sender]
18
+ end
19
+ end
@@ -4,6 +4,7 @@ describe Invitation do
4
4
  it { should validate_presence_of(:account_id) }
5
5
  it { should validate_presence_of(:email) }
6
6
  it { should belong_to(:account) }
7
+ it { should belong_to(:sender) }
7
8
  it { should have_and_belong_to_many(:projects) }
8
9
 
9
10
  it { should_not allow_mass_assignment_of(:account_id) }
@@ -55,6 +56,14 @@ describe Invitation, "saved" do
55
56
  it "uses the code in the url" do
56
57
  subject.to_param.should == code
57
58
  end
59
+
60
+ it "delegates sender email" do
61
+ subject.sender_email.should == subject.sender.email
62
+ end
63
+
64
+ it "delegates sender name" do
65
+ subject.sender_name.should == subject.sender.name
66
+ end
58
67
  end
59
68
 
60
69
  describe Invitation, "valid accept for a new user" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saucy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 89
4
+ hash: 71
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 39
10
- version: 0.2.39
9
+ - 40
10
+ version: 0.2.40
11
11
  platform: ruby
12
12
  authors:
13
13
  - thoughtbot, inc.
@@ -241,6 +241,7 @@ files:
241
241
  - spec/controllers/projects_controller_spec.rb
242
242
  - spec/environment.rb
243
243
  - spec/layouts_spec.rb
244
+ - spec/mailers/invitiation_mailer_spec.rb
244
245
  - spec/models/account_spec.rb
245
246
  - spec/models/invitation_spec.rb
246
247
  - spec/models/limit_spec.rb