cirandas.net

ref: master

test/functional/environment_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
require 'test_helper'

class EnvironmentEmailTemplatesControllerTest < ActionController::TestCase

  setup do
    @email_template = EmailTemplate.create!(:name => 'template', :owner => Environment.default)
    person = create_user_with_permission('template_manager', 'manage_email_templates', Environment.default)
    login_as(person.user.login)
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:email_templates)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

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

    assert_redirected_to url_for(:action => :index)
  end

  test "should show email_template" do
    get :show, id: @email_template
    assert_response :success
  end

  test "should get edit" do
    get :edit, id: @email_template
    assert_response :success
  end

  test "should update email_template" do
    put :update, id: @email_template, email_template: {  }
    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
    end

    assert_redirected_to url_for(:action => :index)
  end

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

end