cirandas.net

ref: master

test/functional/profile_email_templates_controller_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'test_helper'

class ProfileEmailTemplatesControllerTest < ActionController::TestCase

  setup do
    @profile = fast_create(Community)
    @person = create_user_with_permission('templatemanager', 'manage_email_templates', @profile)
    @email_template = EmailTemplate.create!(:name => 'template', :owner => @profile)
    login_as(@person.user.login)
  end

  attr_accessor :profile, :person

  test "should get index" do
    get :index, :profile => profile.identifier
    assert_response :success
    assert_not_nil assigns(:email_templates)
  end

  test "should get new" do
    get :new, :profile => profile.identifier
    assert_response :success
  end

  test "should create email_template" do
    assert_difference('EmailTemplate.count') do
      post :create, email_template: { :name => 'test' }, :profile => profile.identifier
    end

    assert_redirected_to url_for(:action => :index)
  end

  test "should show email_template" do
    get :show, id: @email_template, :profile => profile.identifier
    assert_response :success
  end

  test "should get edit" do
    get :edit, id: @email_template, :profile => profile.identifier
    assert_response :success
  end

  test "should update email_template" do
    put :update, id: @email_template, email_template: {  }, :profile => profile.identifier
    assert_redirected_to url_for(:action => :index)
  end

  test "should destroy email_template" do
    assert_difference('EmailTemplate.count', -1) do
      delete :destroy, id: @email_template, :profile => profile.identifier
    end

    assert_redirected_to url_for(:action => :index)
  end

  test "should get parsed template" do
    environment = Environment.default
    @email_template.subject = '{{profile_name}} - {{environment_name}}'
    @email_template.body = '{{profile_name}} - {{environment_name}}'
    @email_template.save!
    get :show_parsed, id: @email_template, :profile => profile.identifier
    assert_response :success
    json_response = ActiveSupport::JSON.decode(@response.body)
    assert_equal "#{@person.name} - #{environment.name}", json_response['parsed_subject']
    assert_equal "#{@person.name} - #{environment.name}", json_response['parsed_body']
  end

end