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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe PublicBodyChangeRequestsController, "making a new change request" do
it "should show the form" do
get :new
response.should render_template("new")
end
end
describe PublicBodyChangeRequestsController, "creating a change request" do
context 'when handling a request for a new authority' do
before do
@email = "test@example.com"
name = "Test User"
@change_request_params = {:user_email => @email,
:user_name => name,
:public_body_name => 'New Body',
:public_body_email => 'new_body@example.com',
:notes => 'Please',
:source => 'http://www.example.com',
:comment => '' }
end
it "should send an email to the site contact address" do
post :create, {:public_body_change_request => @change_request_params}
change_request_id = assigns[:change_request].id
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
mail.subject.should =~ /Add authority - New Body/
mail.from.should include(@email)
mail.to.should include('postmaster@localhost')
mail.body.should include('new_body@example.com')
mail.body.should include('New Body')
mail.body.should include("Please")
mail.body.should include("http://test.host/admin/bodies/new?change_request_id=#{change_request_id}")
mail.body.should include("http://test.host/admin/change_requests/#{change_request_id}/edit")
end
it 'should show a notice' do
post :create, {:public_body_change_request => @change_request_params}
expected_text = "Your request to add an authority has been sent. Thank you for getting in touch! We'll get back to you soon."
flash[:notice].should == expected_text
end
it 'should redirect to the frontpage' do
post :create, {:public_body_change_request => @change_request_params}
response.should redirect_to frontpage_url
end
it 'has rudimentary spam protection' do
spam_request_params = @change_request_params.merge({ :comment => 'I AM A SPAMBOT' })
post :create, { :public_body_change_request => spam_request_params }
response.should redirect_to(frontpage_path)
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 0
deliveries.clear
end
end
context 'when handling a request for an update to an existing authority' do
before do
@email = "test@example.com"
name = "Test User"
@public_body = FactoryGirl.create(:public_body)
@change_request_params = {:user_email => @email,
:user_name => name,
:public_body_id => @public_body.id,
:public_body_email => 'new_body@example.com',
:notes => 'Please',
:source => 'http://www.example.com',
:comment => '' }
end
it 'should send an email to the site contact address' do
post :create, {:public_body_change_request => @change_request_params}
change_request_id = assigns[:change_request].id
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
mail.subject.should =~ /Update email address - #{@public_body.name}/
mail.from.should include(@email)
mail.to.should include('postmaster@localhost')
mail.body.should include('new_body@example.com')
mail.body.should include(@public_body.name)
mail.body.should include("Please")
mail.body.should include("http://test.host/admin/bodies/#{@public_body.id}/edit?change_request_id=#{change_request_id}")
mail.body.should include("http://test.host/admin/change_requests/#{change_request_id}/edit")
end
it 'should show a notice' do
post :create, {:public_body_change_request => @change_request_params}
expected_text = "Your request to update the address for #{@public_body.name} has been sent. Thank you for getting in touch! We'll get back to you soon."
flash[:notice].should == expected_text
end
it 'should redirect to the frontpage' do
post :create, {:public_body_change_request => @change_request_params}
response.should redirect_to frontpage_url
end
end
end
|