A bit of refactoring on the invitation spec. Remove old pending specs.
This commit is contained in:
parent
c3612ee66d
commit
69c0d8e1d9
1 changed files with 60 additions and 68 deletions
|
|
@ -184,7 +184,7 @@ describe Invitation do
|
|||
user.save!
|
||||
message = "How've you been?"
|
||||
lambda {
|
||||
new_user = Invitation.invite(:from => user, :service => 'email', :identifier => @email, :into => aspect, :message => message)
|
||||
Invitation.invite(:from => user, :service => 'email', :identifier => @email, :into => aspect, :message => message)
|
||||
}.should_not change(user, :invites)
|
||||
end
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ describe Invitation do
|
|||
end
|
||||
|
||||
describe '.create_invitee' do
|
||||
context 'with an existing invitee' do
|
||||
context "when we're resending an invitation" do
|
||||
before do
|
||||
@valid_params = {:from => user,
|
||||
:service => 'email',
|
||||
|
|
@ -208,27 +208,27 @@ describe Invitation do
|
|||
@invitee = Invitation.create_invitee(:service => 'email', :identifier => @email)
|
||||
@valid_params[:existing_user] = @invitee
|
||||
end
|
||||
it 'creates no user' do
|
||||
@valid_params[:existing_user] = @invitee
|
||||
lambda {
|
||||
Invitation.create_invitee(@valid_params)
|
||||
}.should_not change(User, :count)
|
||||
|
||||
it "does not create a user" do
|
||||
expect { Invitation.create_invitee(@valid_params) }.should_not change(User, :count)
|
||||
end
|
||||
it 'sends mail' do
|
||||
lambda {
|
||||
|
||||
it "sends mail" do
|
||||
expect {
|
||||
Invitation.create_invitee(@valid_params)
|
||||
}.should change { Devise.mailer.deliveries.size }.by(1)
|
||||
end
|
||||
it 'does not set the key' do
|
||||
lambda {
|
||||
|
||||
it "does not set the key" do
|
||||
expect {
|
||||
Invitation.create_invitee(@valid_params)
|
||||
}.should_not change { @invitee.reload.serialized_private_key }
|
||||
end
|
||||
it 'does not change the invitation token' do
|
||||
pending "until this passes, old invitation emails will be invalidated by new ones"
|
||||
lambda {
|
||||
|
||||
it "changes the invitation token" do
|
||||
old_token = @invitee.invitation_token
|
||||
Invitation.create_invitee(@valid_params)
|
||||
}.should_not change{@invitee.reload.invitation_token}
|
||||
@invitee.reload.invitation_token.should_not == old_token
|
||||
end
|
||||
end
|
||||
context 'with an inviter' do
|
||||
|
|
@ -237,63 +237,56 @@ describe Invitation do
|
|||
@valid_params = {:from => user, :service => 'email', :identifier => @email, :into => aspect, :message => @message}
|
||||
end
|
||||
|
||||
it 'sends mail' do
|
||||
lambda {
|
||||
it "sends mail" do
|
||||
expect {
|
||||
Invitation.create_invitee(@valid_params)
|
||||
}.should change { Devise.mailer.deliveries.size }.by(1)
|
||||
end
|
||||
|
||||
it 'mails the optional message' do
|
||||
new_user = Invitation.create_invitee(@valid_params)
|
||||
Devise.mailer.deliveries.first.to_s.include?(@message).should be_true
|
||||
it "includes the message in the email" do
|
||||
Invitation.create_invitee(@valid_params)
|
||||
Devise.mailer.deliveries.last.to_s.should include(@message)
|
||||
end
|
||||
|
||||
it 'has no translation missing' do
|
||||
new_user = Invitation.create_invitee(@valid_params)
|
||||
Devise.mailer.deliveries.first.body.raw_source.match(/(translation_missing.+)/).should be_nil
|
||||
it "has no translation missing" do
|
||||
Invitation.create_invitee(@valid_params)
|
||||
Devise.mailer.deliveries.last.body.raw_source.should_not match(/(translation_missing.+)/)
|
||||
end
|
||||
|
||||
it "doesn't create an invitation if the email is invalid" do
|
||||
it "doesn't create a user if the email is invalid" do
|
||||
new_user = Invitation.create_invitee(@valid_params.merge(:identifier => 'fdfdfdfdf'))
|
||||
new_user.should_not be_persisted
|
||||
new_user.should have(1).error_on(:email)
|
||||
end
|
||||
|
||||
it 'does not save a user with an empty string email' do
|
||||
it "does not save a user with an empty string email" do
|
||||
@valid_params[:service] = 'facebook'
|
||||
@valid_params[:identifier] = '3423423'
|
||||
Invitation.create_invitee(@valid_params)
|
||||
@valid_params[:identifier] = 'dfadsfdas'
|
||||
lambda {
|
||||
Invitation.create_invitee(@valid_params)
|
||||
}.should_not raise_error
|
||||
expect { Invitation.create_invitee(@valid_params) }.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with no inviter' do
|
||||
it 'sends an email that includes the right things' do
|
||||
Invitation.create_invitee(:service => 'email', :identifier => @email)
|
||||
Devise.mailer.deliveries.first.to_s.include?("Welcome #{@email}").should == true
|
||||
Devise.mailer.deliveries.first.to_s.should include("Welcome #{@email}")
|
||||
end
|
||||
it 'creates a user' do
|
||||
lambda {
|
||||
expect {
|
||||
Invitation.create_invitee(:service => 'email', :identifier => @email)
|
||||
}.should change(User, :count).by(1)
|
||||
end
|
||||
it 'sends email to the invited user' do
|
||||
lambda {
|
||||
expect {
|
||||
Invitation.create_invitee(:service => 'email', :identifier => @email)
|
||||
}.should change { Devise.mailer.deliveries.size }.by(1)
|
||||
end
|
||||
it 'does not render nonsensical emails' do
|
||||
it 'does not create an invitation' do
|
||||
expect {
|
||||
Invitation.create_invitee(:service => 'email', :identifier => @email)
|
||||
Devise.mailer.deliveries.first.body.raw_source.match(/have invited you to join/i).should be_false
|
||||
end
|
||||
it 'creates an invitation' do
|
||||
pending "Invitations should be more flexible, allowing custom messages to be passed in without an inviter."
|
||||
lambda {
|
||||
Invitation.create_invitee(:service => 'email', :identifier => @email)
|
||||
}.should change(Invitation, :count).by(1)
|
||||
}.should_not change(Invitation, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -318,8 +311,7 @@ describe Invitation do
|
|||
:email => @email,
|
||||
:password => "secret",
|
||||
:password_confirmation => "secret",
|
||||
:person => {:profile => {:first_name => "Bob",
|
||||
:last_name => "Smith"}}}
|
||||
:person => {:profile => {:first_name => "Bob", :last_name => "Smith"}}}
|
||||
@new_user.setup(acceptance_params)
|
||||
@new_user.person.save
|
||||
@new_user.save
|
||||
|
|
|
|||
Loading…
Reference in a new issue