radiant-database_mailer-extension 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +159 -0
- data/Rakefile +120 -0
- data/app/controllers/admin/form_datas_controller.rb +77 -0
- data/app/controllers/database_mailer_processing.rb +19 -0
- data/app/helpers/admin/form_datas_helper.rb +57 -0
- data/app/models/form_data.rb +93 -0
- data/app/models/form_data_asset.rb +14 -0
- data/app/views/admin/form_datas/_export.html.haml +33 -0
- data/app/views/admin/form_datas/_filters.html.haml +27 -0
- data/app/views/admin/form_datas/index.html.haml +34 -0
- data/app/views/admin/form_datas/show.html.haml +49 -0
- data/config/routes.rb +7 -0
- data/database_mailer_extension.rb +31 -0
- data/db/migrate/001_create_form_datas.rb +16 -0
- data/db/migrate/002_add_data_columns.rb +13 -0
- data/db/migrate/20090722135916_create_form_data_assets.rb +21 -0
- data/features/datasets/database_mailer_dataset.rb +19 -0
- data/features/datasets/mailers_dataset.rb +69 -0
- data/features/fixtures/attachment.jpg +0 -0
- data/features/saving_emails_to_database.feature +45 -0
- data/features/step_definitions/admin_steps.rb +6 -0
- data/features/step_definitions/email_steps.rb +73 -0
- data/features/step_definitions/form_data_steps.rb +3 -0
- data/features/step_definitions/webrat_steps.rb +119 -0
- data/features/support/env.rb +28 -0
- data/features/support/paths.rb +25 -0
- data/lib/radiant-database_mailer-extension.rb +8 -0
- data/lib/tasks/database_mailer_extension_tasks.rake +31 -0
- data/public/javascripts/admin/database_mailer.js +73 -0
- data/public/stylesheets/sass/admin/database_mailer.sass +235 -0
- data/radiant-database_mailer-extension.gemspec +26 -0
- data/spec/controllers/form_datas_controller_spec.rb +272 -0
- data/spec/controllers/mail_controller_spec.rb +40 -0
- data/spec/helpers/form_datas_helper_spec.rb +5 -0
- data/spec/models/form_data_asset_spec.rb +11 -0
- data/spec/models/form_data_spec.rb +151 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/views/index.html.erb_spec.rb +25 -0
- metadata +139 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
.clearfix:after
|
2
|
+
:content "."
|
3
|
+
:display block
|
4
|
+
:height 0
|
5
|
+
:clear both
|
6
|
+
:visibility hidden
|
7
|
+
.clearfix
|
8
|
+
:display inline-block
|
9
|
+
.clearfix
|
10
|
+
:display block
|
11
|
+
|
12
|
+
.grey
|
13
|
+
:background-color #9E9E9E
|
14
|
+
:height 21px
|
15
|
+
:margin -20px -20px 0 -20px
|
16
|
+
|
17
|
+
table.results
|
18
|
+
:width 100%
|
19
|
+
a
|
20
|
+
&.sort_asc
|
21
|
+
background: transparent url(/images/admin/metadata_toggle.png) no-repeat scroll 95% 5px
|
22
|
+
padding-right: 15px
|
23
|
+
|
24
|
+
&.sort_desc
|
25
|
+
background: transparent url(/images/admin/metadata_toggle.png) no-repeat scroll 95% -23px
|
26
|
+
padding-right: 15px
|
27
|
+
thead
|
28
|
+
th
|
29
|
+
:background-color #7E7E7E
|
30
|
+
:font-weight normal
|
31
|
+
:padding 2px 4px
|
32
|
+
:text-shadow 1px 1px 0 #666666
|
33
|
+
:color white
|
34
|
+
:font-size 90%
|
35
|
+
&.created_at
|
36
|
+
:width 150px
|
37
|
+
&.url, &.exported
|
38
|
+
:width 200px
|
39
|
+
&.actions
|
40
|
+
:width 100px
|
41
|
+
a
|
42
|
+
:text-shadow 1px 1px 0 #666666
|
43
|
+
:color white
|
44
|
+
:font-size 90%
|
45
|
+
tbody
|
46
|
+
tr:hover
|
47
|
+
:background-color #ecf4ff
|
48
|
+
td
|
49
|
+
:border-bottom 1px solid #F0F0F0
|
50
|
+
:padding 8px 4px
|
51
|
+
:text-align left
|
52
|
+
:vertical-align top
|
53
|
+
&.actions a
|
54
|
+
:color black
|
55
|
+
:text-decoration none
|
56
|
+
&:hover
|
57
|
+
:text-decoration underline
|
58
|
+
tfoot
|
59
|
+
th
|
60
|
+
:background-color #7E7E7E
|
61
|
+
:font-weight normal
|
62
|
+
:padding 2px 4px
|
63
|
+
:text-shadow 1px 1px 0 #666666
|
64
|
+
:color white
|
65
|
+
:font-size 90%
|
66
|
+
:vertical-align middle
|
67
|
+
a
|
68
|
+
:text-shadow 1px 1px 0 #666666
|
69
|
+
:color white
|
70
|
+
:font-size 90%
|
71
|
+
|
72
|
+
.pagination
|
73
|
+
:text-align center
|
74
|
+
:float right
|
75
|
+
:margin-right 20px
|
76
|
+
a
|
77
|
+
:text-shadow 1px 1px 0 #666666
|
78
|
+
:color white
|
79
|
+
:font-size 90%
|
80
|
+
:padding .2em .3em
|
81
|
+
:text-decoration none
|
82
|
+
&:hover, &:focus
|
83
|
+
:text-decoration underline
|
84
|
+
span
|
85
|
+
:padding .2em .3em
|
86
|
+
&.disabled
|
87
|
+
:color #CCC
|
88
|
+
&.current
|
89
|
+
:font-weight bold
|
90
|
+
:background-color #cac8c0
|
91
|
+
:display inline-block
|
92
|
+
:padding 3px 8px
|
93
|
+
:-webkit-border-radius 12px
|
94
|
+
:-moz-border-radius 12px
|
95
|
+
|
96
|
+
#filtering
|
97
|
+
position: relative
|
98
|
+
:height 35px
|
99
|
+
a.expand
|
100
|
+
:-moz-border-radius-bottomleft 6px
|
101
|
+
:-moz-border-radius-bottomright 6px
|
102
|
+
:-webkit-border-bottom-left-radius 6px
|
103
|
+
:-webkit-border-bottom-right-radius 6px
|
104
|
+
:text-shadow 1px 1px 0 #666666
|
105
|
+
:outline none
|
106
|
+
:z-index 100
|
107
|
+
:padding 3px 20px 3px 10px
|
108
|
+
:color #000
|
109
|
+
:position absolute
|
110
|
+
:background #7E7E7E url(/images/admin/metadata_toggle.png) no-repeat 92% 8px
|
111
|
+
:cursor pointer
|
112
|
+
:color white
|
113
|
+
:text-decoration none
|
114
|
+
:font-size 80%
|
115
|
+
.expanded a.expand
|
116
|
+
:-moz-border-radius-topleft 6px
|
117
|
+
:-moz-border-radius-topright 6px
|
118
|
+
:-moz-border-radius-bottomleft 0
|
119
|
+
:-moz-border-radius-bottomright 0
|
120
|
+
:-webkit-border-top-left-radius 6px
|
121
|
+
:-webkit-border-top-right-radius 6px
|
122
|
+
:-webkit-border-bottom-left-radius 0
|
123
|
+
:-webkit-border-bottom-right-radius 0
|
124
|
+
:background #7E7E7E url(/images/admin/metadata_toggle.png) no-repeat 92% -20px
|
125
|
+
|
126
|
+
#x_expander
|
127
|
+
right: 0
|
128
|
+
|
129
|
+
#form, #x_form
|
130
|
+
background-color: #7E7E7E
|
131
|
+
z-index: 10
|
132
|
+
position: absolute
|
133
|
+
top: 22px
|
134
|
+
width: 350px
|
135
|
+
:-moz-border-radius 6px
|
136
|
+
:-webkit-border-radius 6px
|
137
|
+
:border 1px solid #999999
|
138
|
+
border-top-left-radius: 6px
|
139
|
+
border-top-right-radius: 6px
|
140
|
+
:color white
|
141
|
+
input[type="text"]
|
142
|
+
:width 210px
|
143
|
+
a.close
|
144
|
+
:background transparent url('/images/admin/tab_close.png') no-repeat left top
|
145
|
+
:text-indent -9999px
|
146
|
+
:display block
|
147
|
+
:width 16px
|
148
|
+
:height 16px
|
149
|
+
:float right
|
150
|
+
:margin 0 5px 5px 0
|
151
|
+
|
152
|
+
#form
|
153
|
+
:-webkit-border-top-left-radius 0
|
154
|
+
:-moz-border-radius-topleft 0
|
155
|
+
a
|
156
|
+
:color white
|
157
|
+
:text-decoration none
|
158
|
+
&:hover
|
159
|
+
:text-decoration underline
|
160
|
+
|
161
|
+
#x_form
|
162
|
+
right: 0
|
163
|
+
:-moz-border-radius-topright 0
|
164
|
+
:-webkit-border-top-right-radius 0
|
165
|
+
:padding 5px 0 0 5px
|
166
|
+
|
167
|
+
table.search
|
168
|
+
:width 340px
|
169
|
+
:margin-left 5px
|
170
|
+
tr
|
171
|
+
:border-top 1px solid #999999
|
172
|
+
&:first-child
|
173
|
+
:border none
|
174
|
+
th, td
|
175
|
+
:padding 5px
|
176
|
+
:vertical-align middle
|
177
|
+
th
|
178
|
+
:width 100px
|
179
|
+
label
|
180
|
+
:color white
|
181
|
+
:font-size 80%
|
182
|
+
td
|
183
|
+
:width 220px
|
184
|
+
|
185
|
+
table.export
|
186
|
+
:width 340px
|
187
|
+
:margin-left 5px
|
188
|
+
tr
|
189
|
+
:border-top 1px solid #999999
|
190
|
+
&:first-child
|
191
|
+
:border none
|
192
|
+
th
|
193
|
+
:padding 3px 0 3px 5px
|
194
|
+
td
|
195
|
+
:padding 3px 5px 3px 0
|
196
|
+
|
197
|
+
#current_filters
|
198
|
+
margin-left: 100px
|
199
|
+
padding-top: 3px
|
200
|
+
position: absolute
|
201
|
+
width: 600px
|
202
|
+
|
203
|
+
a
|
204
|
+
color: #000
|
205
|
+
|
206
|
+
#show
|
207
|
+
a.back
|
208
|
+
:color red
|
209
|
+
:font-size 80%
|
210
|
+
:text-decoration none
|
211
|
+
&:hover
|
212
|
+
:text-decoration underline
|
213
|
+
.page
|
214
|
+
:min-height 350px
|
215
|
+
table.result
|
216
|
+
:width 96%
|
217
|
+
:margin-left 2%
|
218
|
+
tr
|
219
|
+
:border-bottom 1px solid #ccc
|
220
|
+
th
|
221
|
+
:font-weight bold
|
222
|
+
th, td
|
223
|
+
:padding 5px 10px
|
224
|
+
:vertical-align top
|
225
|
+
table.attachments
|
226
|
+
:width 700px
|
227
|
+
tr
|
228
|
+
:border-bottom 1px solid #ccc
|
229
|
+
th
|
230
|
+
:font-weight bold
|
231
|
+
th, td
|
232
|
+
:padding 5px 10px
|
233
|
+
:vertical-align top
|
234
|
+
a
|
235
|
+
:color black
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "radiant-database_mailer-extension"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-database_mailer-extension"
|
7
|
+
s.version = RadiantDatabaseMailerExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = RadiantDatabaseMailerExtension::AUTHORS
|
10
|
+
s.email = RadiantDatabaseMailerExtension::EMAIL
|
11
|
+
s.homepage = RadiantDatabaseMailerExtension::URL
|
12
|
+
s.summary = RadiantDatabaseMailerExtension::SUMMARY
|
13
|
+
s.description = RadiantDatabaseMailerExtension::DESCRIPTION
|
14
|
+
|
15
|
+
ignores = if File.exist?('.gitignore')
|
16
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
17
|
+
else
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
s.files = Dir['**/*'] - ignores
|
21
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
22
|
+
# s.executables = Dir['bin/*'] - ignores
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
s.add_dependency 'radiant-mailer-extension', '~> 1.0.3'
|
26
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::FormDatasController do
|
4
|
+
dataset :users
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
login_as :designer
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'handling GET index' do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@form_datas = (1..10).map {|i| mock_model(FormData) }
|
14
|
+
@urls = (1..4).map {|i| mock_model(FormData)}
|
15
|
+
|
16
|
+
FormData.stub!(:form_paginate).and_return(@form_datas)
|
17
|
+
FormData.stub!(:find_all_group_by_url).and_return(@urls)
|
18
|
+
@list_params = mock("list_params")
|
19
|
+
controller.stub!(:filter_by_params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def do_get
|
23
|
+
get :index
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be succesful" do
|
27
|
+
do_get
|
28
|
+
response.should be_success
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should render index template" do
|
32
|
+
do_get
|
33
|
+
response.should render_template('index')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should parse list_params" do
|
37
|
+
controller.should_receive(:filter_by_params).with(FormData::FILTER_COLUMNS)
|
38
|
+
do_get
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should find all saved items with list_params" do
|
42
|
+
controller.should_receive(:list_params).and_return(@list_params)
|
43
|
+
FormData.should_receive(:form_paginate).with(@list_params).and_return(@form_datas)
|
44
|
+
do_get
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should assign the found saved items for the view" do
|
48
|
+
do_get
|
49
|
+
assigns[:saved_items].should == @form_datas
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should assign the found urls for the view" do
|
53
|
+
do_get
|
54
|
+
assigns[:urls].should == @urls
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "handling GET show" do
|
59
|
+
before(:each) do
|
60
|
+
@form_data = mock_model(FormData)
|
61
|
+
FormData.stub!(:find).and_return(@form_data)
|
62
|
+
end
|
63
|
+
|
64
|
+
def do_get
|
65
|
+
get :show, :id => @form_data.id
|
66
|
+
end
|
67
|
+
|
68
|
+
it "is successful" do
|
69
|
+
do_get
|
70
|
+
response.should be_success
|
71
|
+
end
|
72
|
+
|
73
|
+
it "finds the corresponding form_data and assigns it to the view" do
|
74
|
+
FormData.should_receive(:find).with(@form_data.id.to_s).and_return(@form_data)
|
75
|
+
do_get
|
76
|
+
assigns[:form_data].should == @form_data
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'handling GET index.csv' do
|
82
|
+
before do
|
83
|
+
@list_params = mock("list_params")
|
84
|
+
controller.stub!(:list_params).and_return(@list_params)
|
85
|
+
controller.stub!(:filter_by_params)
|
86
|
+
|
87
|
+
t = Time.now
|
88
|
+
@time = mock("time", :to_s => 'time', :to_f => t.to_f, :to_i => t.to_i, :strftime => 'time')
|
89
|
+
Time.stub!(:now).and_return(@time)
|
90
|
+
|
91
|
+
FormData.stub!(:export_csv).and_return('csv')
|
92
|
+
controller.stub!(:send_data)
|
93
|
+
|
94
|
+
@request.accept = "text/csv" #=> request JS
|
95
|
+
end
|
96
|
+
|
97
|
+
def do_get(options={})
|
98
|
+
get :index, options, :format => 'csv'
|
99
|
+
end
|
100
|
+
|
101
|
+
it "is succesful" do
|
102
|
+
do_get
|
103
|
+
response.should be_redirect
|
104
|
+
end
|
105
|
+
|
106
|
+
it "parses list_params" do
|
107
|
+
controller.should_receive(:filter_by_params).with(FormData::FILTER_COLUMNS)
|
108
|
+
do_get
|
109
|
+
end
|
110
|
+
|
111
|
+
it "passes the selected_export_columns" do
|
112
|
+
FormData.should_receive(:export_csv).with(@list_params, %w(name url), @time, false).and_return('csv')
|
113
|
+
do_get({:export_name => "name", :export_url => "url"})
|
114
|
+
end
|
115
|
+
|
116
|
+
it "passes the include_all columns" do
|
117
|
+
FormData.should_receive(:export_csv).with(@list_params, [], @time, true).and_return('csv')
|
118
|
+
do_get({:include_all => "yes"})
|
119
|
+
end
|
120
|
+
|
121
|
+
it "sends data as csv string" do
|
122
|
+
FormData.should_receive(:export_csv).and_return('csv_string')
|
123
|
+
controller.should_receive(:send_data).with("csv_string", {:type=>"text/csv", :filename=>"export_#{@time.to_s}.csv", :disposition=>"attachment"})
|
124
|
+
do_get
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "handling GET index.xls" do
|
129
|
+
before do
|
130
|
+
@list_params = mock("list_params")
|
131
|
+
controller.stub!(:list_params).and_return(@list_params)
|
132
|
+
controller.stub!(:filter_by_params)
|
133
|
+
|
134
|
+
t = Time.now
|
135
|
+
@time = mock("time", :to_s => 'time', :to_f => t.to_f, :to_i => t.to_i, :strftime => 'time')
|
136
|
+
Time.stub!(:now).and_return(@time)
|
137
|
+
|
138
|
+
FormData.stub!(:export_xls).and_return('xls')
|
139
|
+
controller.stub!(:send_file)
|
140
|
+
end
|
141
|
+
|
142
|
+
def do_get(options={})
|
143
|
+
get :index, options.merge(:format => 'xls')
|
144
|
+
end
|
145
|
+
|
146
|
+
it "is succesful" do
|
147
|
+
do_get
|
148
|
+
response.should be_success
|
149
|
+
end
|
150
|
+
|
151
|
+
it "parses list_params" do
|
152
|
+
controller.should_receive(:filter_by_params).with(FormData::FILTER_COLUMNS)
|
153
|
+
do_get
|
154
|
+
end
|
155
|
+
|
156
|
+
it "passes the selected_export_columns" do
|
157
|
+
FormData.should_receive(:export_xls).with(@list_params, %w(name url), @time, false).and_return('xls')
|
158
|
+
do_get({:export_name => "name", :export_url => "url"})
|
159
|
+
end
|
160
|
+
|
161
|
+
it "passes the include_all columns" do
|
162
|
+
FormData.should_receive(:export_xls).with(@list_params, [], @time, true).and_return('xls')
|
163
|
+
do_get({:include_all => "yes"})
|
164
|
+
end
|
165
|
+
|
166
|
+
it "sends data as csv string" do
|
167
|
+
FormData.should_receive(:export_xls).and_return('xls_file')
|
168
|
+
controller.should_receive(:send_file).with("xls_file", {:type=>"application/vnd.ms-excel", :filename=>"form_data_#{@time.to_s}.xls", :disposition=>"attachment"})
|
169
|
+
do_get
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "parsing list_params" do
|
175
|
+
|
176
|
+
def do_get(options={})
|
177
|
+
get :index, options
|
178
|
+
end
|
179
|
+
|
180
|
+
def filter_by_params(args=[])
|
181
|
+
@controller.send(:filter_by_params, args)
|
182
|
+
end
|
183
|
+
|
184
|
+
def list_params
|
185
|
+
@controller.send(:list_params)
|
186
|
+
end
|
187
|
+
|
188
|
+
def set_cookie(key, value)
|
189
|
+
# request.cookies[key] = CGI::Cookie.new('name' => key, 'value' => value)
|
190
|
+
request.cookies[key] = value
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should have default set of params" do
|
194
|
+
do_get
|
195
|
+
filter_by_params
|
196
|
+
[:page, :sort_by, :sort_order].each {|p| response.cookies.keys.should include(p.to_s)}
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should take arbitrary params" do
|
200
|
+
do_get(:name => 'Blah', :test => 10)
|
201
|
+
filter_by_params([:name, :test])
|
202
|
+
[:name, :test].each {|p| response.cookies.keys.should include(p.to_s)}
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should load list_params from cookies by default" do
|
206
|
+
set_cookie('page', '98')
|
207
|
+
do_get
|
208
|
+
filter_by_params
|
209
|
+
list_params[:page].should == '98'
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should prefer request params over cookies" do
|
213
|
+
set_cookie('page', '98')
|
214
|
+
do_get(:page => '99')
|
215
|
+
filter_by_params
|
216
|
+
list_params[:page].should == '99'
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should update cookies with new values" do
|
220
|
+
set_cookie('page', '98')
|
221
|
+
do_get(:page => '99')
|
222
|
+
filter_by_params
|
223
|
+
response.cookies['page'].should == '99'
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should reset list_params when params[:reset] == 1" do
|
227
|
+
set_cookie('page', '98')
|
228
|
+
do_get(:reset => 1)
|
229
|
+
filter_by_params
|
230
|
+
response.cookies['page'].should == "1"
|
231
|
+
end
|
232
|
+
it "should set params[:page] if loading from cookies (required for will_paginate to work)" do
|
233
|
+
set_cookie('page', '98')
|
234
|
+
do_get
|
235
|
+
filter_by_params
|
236
|
+
params[:page].should == '98'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "handling DELETE destroy" do
|
241
|
+
|
242
|
+
before do
|
243
|
+
@form_data = mock_model(FormData)
|
244
|
+
FormData.stub!(:find).and_return(@form_data)
|
245
|
+
@form_data.stub!(:destroy)
|
246
|
+
end
|
247
|
+
|
248
|
+
def do_delete
|
249
|
+
delete :destroy, :id => @form_data.id
|
250
|
+
end
|
251
|
+
|
252
|
+
it "finds the coresponding record" do
|
253
|
+
FormData.should_receive(:find).with(@form_data.id.to_s).and_return(@form_data)
|
254
|
+
do_delete
|
255
|
+
end
|
256
|
+
|
257
|
+
it "destroys the record" do
|
258
|
+
@form_data.should_receive(:destroy)
|
259
|
+
do_delete
|
260
|
+
end
|
261
|
+
|
262
|
+
it "assigns flash message" do
|
263
|
+
do_delete
|
264
|
+
flash[:notice].should == "Record deleted!"
|
265
|
+
end
|
266
|
+
|
267
|
+
it "redirects on success" do
|
268
|
+
do_delete
|
269
|
+
response.should be_redirect
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe MailController do
|
4
|
+
dataset :users, :mailers
|
5
|
+
|
6
|
+
before do
|
7
|
+
login_as :designer
|
8
|
+
@form_data = mock_model(FormData)
|
9
|
+
FormData.stub!(:create)
|
10
|
+
end
|
11
|
+
|
12
|
+
def do_post(options={})
|
13
|
+
post :create, {:page_id => page_id(:contact), :mailer => {}}.merge(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "redirects to /contact-success on success" do
|
17
|
+
do_post
|
18
|
+
response.should redirect_to('/contact/thank-you')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "creates a new FormData from mailer params" do
|
22
|
+
FormData.should_receive(:create).and_return(@form_data)
|
23
|
+
do_post
|
24
|
+
end
|
25
|
+
|
26
|
+
it "passes the page url to the new form data" do
|
27
|
+
FormData.should_receive(:create).with("url" => "/contact/", "blob" => "").and_return(@form_data)
|
28
|
+
do_post
|
29
|
+
end
|
30
|
+
|
31
|
+
it "passes mailer params to the new for data" do
|
32
|
+
FormData.should_receive(:create).with("name" => "piki", "url" => "/contact/", "blob" => "").and_return(@form_data)
|
33
|
+
do_post(:mailer => {"name" => 'piki'})
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not create FormData when save_to_database config is false" do
|
37
|
+
FormData.should_not_receive(:create)
|
38
|
+
do_post(:page_id => page_id(:contact_no_save))
|
39
|
+
end
|
40
|
+
end
|