forked from opf/openproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenterprises_controller_spec.rb
More file actions
201 lines (163 loc) · 5.96 KB
/
Copy pathenterprises_controller_spec.rb
File metadata and controls
201 lines (163 loc) · 5.96 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe EnterprisesController, type: :controller do
let(:a_token) { EnterpriseToken.new }
let(:token_attributes) do
{
subscriber: "Foobar",
mail: "foo@example.org",
starts_at: Date.today,
expires_at: nil
}
end
let(:token_object) do
OpenProject::Token.new token_attributes
end
before do
login_as user
allow(a_token).to receive(:token_object).and_return(token_object)
end
context 'with admin' do
let(:user) { FactoryBot.build(:admin) }
describe '#show' do
render_views
context 'when token exists' do
before do
allow(EnterpriseToken).to receive(:current).and_return(a_token)
get :show
end
shared_examples 'it renders the EE overview' do
it 'renders the overview' do
expect(response).to be_successful
expect(response).to render_template 'show'
expect(response).to render_template partial: 'enterprises/_current'
expect(response).to render_template partial: 'enterprises/_form'
end
end
it_behaves_like 'it renders the EE overview'
context 'with version >= 2.0' do
let(:token_attributes) { super().merge version: "2.0" }
context 'with correct domain', with_settings: { host_name: 'community.openproject.com' } do
let(:token_attributes) { super().merge domain: 'community.openproject.com' }
it_behaves_like 'it renders the EE overview'
it "doesn't show any warnings or errors" do
expect(controller).not_to set_flash.now
end
end
context 'with wrong domain', with_settings: { host_name: 'community.openproject.com' } do
let(:token_attributes) { super().merge domain: 'localhost' }
it_behaves_like 'it renders the EE overview'
it "shows an invalid domain error" do
expect(controller).to set_flash.now[:error].to(/.*localhost.*does not match.*community.openproject.com/)
end
end
end
context 'with version < 2.0' do
let(:token_attributes) { super().merge version: "1.0.3" }
context 'with wrong domain', with_settings: { host_name: 'community.openproject.com' } do
let(:token_attributes) { super().merge domain: 'localhost' }
it_behaves_like 'it renders the EE overview'
it "doesn't show any warnings or errors" do
expect(controller).not_to set_flash.now
end
end
end
end
context 'when no token exists' do
before do
allow(EnterpriseToken).to receive(:current).and_return(nil)
get :show
end
it 'still renders #show with form' do
expect(response).not_to render_template partial: 'enterprises/_current'
expect(response.body).to have_selector '.upsale-benefits'
end
end
end
describe '#create' do
let(:params) do
{
enterprise_token: { encoded_token: 'foo' }
}
end
before do
allow(EnterpriseToken).to receive(:current).and_return(nil)
allow(EnterpriseToken).to receive(:new).and_return(a_token)
expect(a_token).to receive(:encoded_token=).with('foo')
expect(a_token).to receive(:save).and_return(valid)
post :create, params: params
end
context 'valid token input' do
let(:valid) { true }
it 'redirects to index' do
expect(controller).to set_flash[:notice].to I18n.t(:notice_successful_update)
expect(response).to redirect_to action: :show
end
end
context 'invalid token input' do
let(:valid) { false }
it 'renders with error' do
expect(response).not_to be_redirect
expect(response).to render_template 'enterprises/show'
end
end
end
describe '#destroy' do
context 'when a token exists' do
before do
expect(EnterpriseToken).to receive(:current).and_return(a_token)
expect(a_token).to receive(:destroy)
delete :destroy
end
it 'redirects to show' do
expect(controller).to set_flash[:notice].to I18n.t(:notice_successful_delete)
expect(response).to redirect_to action: :show
end
end
context 'when no token exists' do
before do
expect(EnterpriseToken).to receive(:current).and_return(nil)
delete :destroy
end
it 'renders 404' do
expect(response.status).to eq(404)
end
end
end
end
context 'regular user' do
let(:user) { FactoryBot.build(:user) }
before do
get :show
end
it 'is forbidden' do
expect(response.status).to eq 403
end
end
end