-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdns_hosted_zones_controller_spec.rb
More file actions
166 lines (134 loc) · 5.91 KB
/
Copy pathdns_hosted_zones_controller_spec.rb
File metadata and controls
166 lines (134 loc) · 5.91 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
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe DnsHostedZonesController, type: :controller do
before do
allow_any_instance_of(DnsService).to receive(:create_hosted_zone).and_return({
'delegation_set' => { 'name_servers' => ["ns-1258.awsdns-29.org", "ns-826.awsdns-39.net", "ns-55.awsdns-06.com", "ns-1552.awsdns-02.co.uk"] },
'hosted_zone' => {'id' => '12312312'}
})
allow_any_instance_of(DnsService).to receive(:delete_hosted_zone)
allow_any_instance_of(DnsService).to receive(:change_resource_record_sets)
allow_any_instance_of(DnsService).to receive(:list_resource_record_sets).and_return([])
allow_any_instance_of(DnsService).to receive(:list_hosted_zones).and_return([])
end
let!(:user) { create(:user) }
let!(:community) { create(:community) }
before do
CommunityUser.create community:community, user: user, role:1
end
# This should return the minimal set of attributes required to create a valid
# DnsHostedZone. As you add validations to DnsHostedZone, be sure to
# adjust the attributes here as well.
let(:valid_attributes) {
{
domain_name: "nossas.org.br",
comment: "new domain for ourcities"
}
}
let(:invalid_attributes) {
{
comment: "new domain for ourcities"
}
}
before { stub_current_user(user) }
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# DnsHostedZonesController. Be sure to keep this updated too.
describe "GET #index" do
let!(:dns_hosted_zone) { create(:dns_hosted_zone, community: community) }
it "assigns all dns_hosted_zones as @dns_hosted_zones" do
get :index, {community_id: community.id}
expect(assigns(:dns_hosted_zones)).to eq([])
end
end
describe "GET #show" do
it "assigns the requested dns_hosted_zone as @dns_hosted_zone" do
dns_hosted_zone = create(:dns_hosted_zone, community: community)
get :show, {community_id: community.id, id: dns_hosted_zone.to_param}
expect(assigns(:dns_hosted_zone)).to eq(dns_hosted_zone)
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new DnsHostedZone" do
expect {
post :create, {community_id: community.id, dns_hosted_zone: valid_attributes, format: :json}
}.to change(DnsHostedZone, :count).by(1)
end
it "assigns a newly created dns_hosted_zone as @dns_hosted_zone" do
post :create, {community_id: community.id, dns_hosted_zone: valid_attributes, format: :json}
expect(assigns(:dns_hosted_zone)).to be_a(DnsHostedZone)
expect(assigns(:dns_hosted_zone)).to be_persisted
end
end
context "with invalid params" do
it "assigns a newly created but unsaved dns_hosted_zone as @dns_hosted_zone" do
post :create, {community_id: community.id, dns_hosted_zone: invalid_attributes, format: :json}
expect(assigns(:dns_hosted_zone)).to be_a_new(DnsHostedZone)
end
end
end
describe "PUT #update" do
let!(:dns_hosted_zone) { create(:dns_hosted_zone, community: community) }
context "with valid params" do
before do
put :update, {community_id: community.id, id: dns_hosted_zone.id, dns_hosted_zone: valid_attributes, format: :json}
end
it { should respond_with(200) }
it "updates the requested dns_hosted_zone" do
dns_hosted_zone.reload
expect(dns_hosted_zone.domain_name).to eq(valid_attributes[:domain_name])
expect(dns_hosted_zone.comment).to eq(valid_attributes[:comment])
end
it "assigns the requested dns_hosted_zone as @dns_hosted_zone" do
expect(assigns(:dns_hosted_zone)).to eq(dns_hosted_zone)
end
end
context "with invalid params" do
before do
put :update, {community_id: community.id, id: dns_hosted_zone.id, dns_hosted_zone: invalid_attributes, format: :json}
end
it "assigns the dns_hosted_zone as @dns_hosted_zone" do
expect(assigns(:dns_hosted_zone)).to eq(dns_hosted_zone)
end
end
end
describe "DELETE #destroy" do
let!(:dns_hosted_zone) { create(:dns_hosted_zone, community: community) }
it "destroys the requested dns_hosted_zone" do
expect {
delete :destroy, {id: dns_hosted_zone.to_param, community_id: community.id}
}.to change(DnsHostedZone, :count).by(-1)
end
end
describe 'GET #check' do
[true, false].each do |checked|
context "returning #{checked}" do
let(:dns_hosted_zone) {create :dns_hosted_zone, ns_ok: checked}
before do
allow_any_instance_of(DnsHostedZone).to receive(:check_ns_correctly_filled!).and_return(checked)
get :check, { community_id: dns_hosted_zone.community.id, dns_hosted_zone_id: dns_hosted_zone.id }
end
it do
expect(assigns(:dns_hosted_zone).ns_ok?).to be checked
end
end
end
end
end