<commit_before>require "spec_helper"

describe UserMailer do
  context 'sending email on membership approval' do
    before :all do
      @user = User.make!
      @group = Group.make!
      @mail = UserMailer.group_membership_approved(@user, @group)
    end

    it 'renders the subject' do
      @mail.subject.should == "[Loomio: #{@group.full_name}] Membership approved"
    end

    it 'renders the receiver email' do
      @mail.to.should == [@user.email]
    end

    it 'assigns correct reply_to' do
      @mail.reply_to.should == [@group.admin_email]
    end

    it 'renders the sender email' do
      @mail.from.should == ['<EMAIL>']
    end

    it 'assigns the @name variable which appears in the email body' do
      @mail.body.encoded.should match(@group.full_name)
    end

    it 'assigns confirmation_url for email body' do
      @mail.body.encoded.should match("http://localhost:3000/groups/#{@group.id}")
    end
  end

  context 'sending email when user is added to a group' do
    before :all do
      @user = User.make!
      @group = Group.make!
      @mail = UserMailer.added_to_group(@user, @group)
    end

    it 'renders the subject' do
      @mail.subject.should match(/been added to a group/)
    end
    it 'renders the receiver email' do
      @mail.to.should == [@user.email]
    end
    
    it 'assigns reply to' do
      @mail.reply_to.should == [@group.admin_email]
    end
    
    it 'renders the sender email' do
      @mail.from.should == ['<EMAIL>']
    end

    it 'assigns the groups name which appears in the email body' do
      @mail.body.encoded.should match(@group.full_name)
    end

    it 'assigns confirmation_url for email body' do
      @mail.body.encoded.should match("http://localhost:3000/groups/#{@group.id}")
    end
  end

  context 'sending email when user is invited to loomio' do
    before :all do
      @inviter = User.make
      @group = Group.make!
      @user = User.invite_and_notify!({email: "<EMAIL>"}, @inviter, @group)
      @mail = UserMailer.invited_to_loomio(@user, @inviter, @group)
    end

    it 'renders the subject' do
      @mail.subject.should match(
        /#{@inviter.name} has invited you to #{@group.full_name} on Loomio/)
    end

    it 'renders the receiver email' do
      @mail.to.should == [@user.email]
    end

    it 'renders the sender email' do
      @mail.from.should == ['<EMAIL>']
    end
    
    it 'assigns correct reply_to' do
      @mail.reply_to.should == [@group.admin_email]
    end

    it 'assigns the groups name which appears in the email body' do
      @mail.body.encoded.should match(@group.full_name)
    end

    it 'assigns inviters name which appears in the email body' do
      @mail.body.encoded.should match(@inviter.name)
    end

    it 'assigns invite_url for email body' do<commit_msg>Refactor mailer to use shared context.<commit_after>require "spec_helper"

describe UserMailer do
  shared_examples_for 'email_meta' do
    it 'renders the receiver email' do
      @mail.to.should == [@user.email]
    end
    
    it 'assigns correct reply_to' do
      @mail.reply_to.should == [@group.admin_email]
    end
    
    it 'renders the sender email' do
      @mail.from.should == ['<EMAIL>']
    end
    
    it 'assigns the @name variable which appears in the email body' do
      @mail.body.encoded.should match(@group.full_name)
    end
  end
  context 'sending email on membership approval' do
    before :all do
      @user = User.make!
      @group = Group.make!
      @mail = UserMailer.group_membership_approved(@user, @group)
    end
    
    it_behaves_like 'email_meta'
    
    it 'renders the subject' do
      @mail.subject.should == "[Loomio: #{@group.full_name}] Membership approved"
    end
    
    it 'assigns confirmation_url for email body' do
      @mail.body.encoded.should match("http://localhost:3000/groups/#{@group.id}")
    end
  end

  context 'sending email when user is added to a group' do
    before :all do
      @user = User.make!
      @group = Group.make!
      @mail = UserMailer.added_to_group(@user, @group)
    end
    
    it_behaves_like 'email_meta'

    it 'renders the subject' do
      @mail.subject.should match(/been added to a group/)
    end

    it 'assigns confirmation_url for email body' do
      @mail.body.encoded.should match("http://localhost:3000/groups/#{@group.id}")
    end
  end

  context 'sending email when user is invited to loomio' do
    before :all do
      @inviter = User.make
      @group = Group.make!
      @user = User.invite_and_notify!({email: "<EMAIL>"}, @inviter, @group)
      @mail = UserMailer.invited_to_loomio(@user, @inviter, @group)
    end
    
    it_behaves_like 'email_meta'

    it 'renders the subject' do
      @mail.subject.should match(
        /#{@inviter.name} has invited you to #{@group.full_name} on Loomio/)
    end

    it 'assigns inviters name which appears in the email body' do
      @mail.body.encoded.should match(@inviter.name)
    end

    it 'assigns invite_url for email body' do
{'fraction_non_alphanumeric': 0.10938433950986252, 'fraction_numerical': 0.0031878860330743176, 'mean_word_length': 2.702064896755162, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7227117', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1612, 'n_words': 486}