Skip to content

Commit 3e06cd7

Browse files
committed
Fix the specs
1 parent 0da35d1 commit 3e06cd7

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

spec/requests/regions_spec.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,45 @@
1515
RSpec.describe "/regions", type: :request do
1616
let(:user) { create(:user) }
1717

18+
include AuthHelper
19+
20+
before do
21+
sign_in(user)
22+
end
23+
1824
# This should return the minimal set of attributes required to create a valid
1925
# Region. As you add validations to Region, be sure to
2026
# adjust the attributes here as well.
21-
let(:valid_attributes) {
22-
skip("Add a hash of attributes valid for your model")
23-
}
27+
let(:valid_attributes) { { name: "Old Region" } }
2428

25-
let(:invalid_attributes) {
26-
skip("Add a hash of attributes invalid for your model")
27-
}
29+
let(:invalid_attributes) { { name: "" } }
2830

2931
describe "GET /index" do
3032
it "renders a successful response" do
31-
Region.create! valid_attributes
33+
region = FactoryBot.create(:region)
3234
get regions_url
3335
expect(response).to be_successful
3436
end
3537
end
3638

3739
describe "GET /show" do
3840
it "renders a successful response" do
39-
region = Region.create! valid_attributes
41+
region = FactoryBot.create(:region)
4042
get region_url(region)
4143
expect(response).to be_successful
4244
end
4345
end
4446

4547
describe "GET /new" do
4648
it "renders a successful response" do
47-
user.sessions.create!
4849
get new_region_url
4950
expect(response).to be_successful
5051
end
5152
end
5253

5354
describe "GET /edit" do
5455
it "renders a successful response" do
55-
region = Region.create! valid_attributes
56+
region = FactoryBot.create(:region)
5657
get edit_region_url(region)
5758
expect(response).to be_successful
5859
end
@@ -88,15 +89,13 @@
8889

8990
describe "PATCH /update" do
9091
context "with valid parameters" do
91-
let(:new_attributes) {
92-
skip("Add a hash of attributes valid for your model")
93-
}
92+
let(:new_attributes) { { name: "Updated Region" } }
9493

9594
it "updates the requested region" do
9695
region = Region.create! valid_attributes
9796
patch region_url(region), params: { region: new_attributes }
9897
region.reload
99-
skip("Add assertions for updated state")
98+
expect(region.name).to eq("Updated Region")
10099
end
101100

102101
it "redirects to the region" do
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module AuthHelper
2+
def sign_in(user)
3+
post session_path, params: { email: user.email, password: user.password }
4+
end
5+
end

0 commit comments

Comments
 (0)