|
15 | 15 | RSpec.describe "/regions", type: :request do |
16 | 16 | let(:user) { create(:user) } |
17 | 17 |
|
| 18 | + include AuthHelper |
| 19 | + |
| 20 | + before do |
| 21 | + sign_in(user) |
| 22 | + end |
| 23 | + |
18 | 24 | # This should return the minimal set of attributes required to create a valid |
19 | 25 | # Region. As you add validations to Region, be sure to |
20 | 26 | # 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" } } |
24 | 28 |
|
25 | | - let(:invalid_attributes) { |
26 | | - skip("Add a hash of attributes invalid for your model") |
27 | | - } |
| 29 | + let(:invalid_attributes) { { name: "" } } |
28 | 30 |
|
29 | 31 | describe "GET /index" do |
30 | 32 | it "renders a successful response" do |
31 | | - Region.create! valid_attributes |
| 33 | + region = FactoryBot.create(:region) |
32 | 34 | get regions_url |
33 | 35 | expect(response).to be_successful |
34 | 36 | end |
35 | 37 | end |
36 | 38 |
|
37 | 39 | describe "GET /show" do |
38 | 40 | it "renders a successful response" do |
39 | | - region = Region.create! valid_attributes |
| 41 | + region = FactoryBot.create(:region) |
40 | 42 | get region_url(region) |
41 | 43 | expect(response).to be_successful |
42 | 44 | end |
43 | 45 | end |
44 | 46 |
|
45 | 47 | describe "GET /new" do |
46 | 48 | it "renders a successful response" do |
47 | | - user.sessions.create! |
48 | 49 | get new_region_url |
49 | 50 | expect(response).to be_successful |
50 | 51 | end |
51 | 52 | end |
52 | 53 |
|
53 | 54 | describe "GET /edit" do |
54 | 55 | it "renders a successful response" do |
55 | | - region = Region.create! valid_attributes |
| 56 | + region = FactoryBot.create(:region) |
56 | 57 | get edit_region_url(region) |
57 | 58 | expect(response).to be_successful |
58 | 59 | end |
|
88 | 89 |
|
89 | 90 | describe "PATCH /update" do |
90 | 91 | 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" } } |
94 | 93 |
|
95 | 94 | it "updates the requested region" do |
96 | 95 | region = Region.create! valid_attributes |
97 | 96 | patch region_url(region), params: { region: new_attributes } |
98 | 97 | region.reload |
99 | | - skip("Add assertions for updated state") |
| 98 | + expect(region.name).to eq("Updated Region") |
100 | 99 | end |
101 | 100 |
|
102 | 101 | it "redirects to the region" do |
|
0 commit comments