|
1 | | -require 'rails_helper' |
| 1 | +require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe CustomLinksController, type: :request do |
4 | 4 | let(:user) { create(:user) } |
5 | 5 | let(:admin) { create(:casa_admin, casa_org: user.casa_org) } |
6 | 6 | let(:custom_link) { create(:custom_link, casa_org_id: user.casa_org_id) } |
7 | | - let(:valid_attributes) { { text: 'Link Text', url: 'http://example.com', active: true, casa_org_id: user.casa_org_id } } |
8 | | - let(:invalid_attributes) { { text: '', url: 'invalid', active: nil } } |
| 7 | + let(:valid_attributes) { {text: "Link Text", url: "http://example.com", active: true, casa_org_id: user.casa_org_id} } |
| 8 | + let(:invalid_attributes) { {text: "", url: "invalid", active: nil} } |
9 | 9 |
|
10 | 10 | before do |
11 | 11 | sign_in user |
|
16 | 16 | allow_any_instance_of(CustomLinkPolicy).to receive(:destroy?).and_return(true) |
17 | 17 | end |
18 | 18 |
|
19 | | - describe 'GET #new' do |
20 | | - it 'authorizes the action' do |
21 | | - expect_any_instance_of(CustomLinkPolicy).to receive(:new?).and_return(true) |
| 19 | + describe "GET #new" do |
| 20 | + it "authorizes the action" do |
| 21 | + allow_any_instance_of(CustomLinkPolicy).to receive(:new?).and_return(true) |
22 | 22 | get new_custom_link_path |
23 | 23 | end |
24 | 24 |
|
25 | | - it 'assigns a new CustomLink with the current user\'s casa_org_id to @custom_link' do |
| 25 | + it "assigns a new CustomLink with the current user's casa_org_id to @custom_link" do |
26 | 26 | get new_custom_link_path |
27 | 27 | expect(assigns(:custom_link)).to be_a_new(CustomLink) |
28 | 28 | expect(assigns(:custom_link).casa_org_id).to eq(user.casa_org_id) |
29 | 29 | end |
30 | 30 |
|
31 | | - it 'renders the new template' do |
| 31 | + it "renders the new template" do |
32 | 32 | get new_custom_link_path |
33 | 33 | expect(response).to render_template(:new) |
34 | 34 | end |
35 | 35 | end |
36 | 36 |
|
37 | | - describe 'GET #edit' do |
38 | | - it 'assigns the requested custom_link as @custom_link' do |
| 37 | + describe "GET #edit" do |
| 38 | + it "assigns the requested custom_link as @custom_link" do |
39 | 39 | get edit_custom_link_path(custom_link) |
40 | 40 | expect(assigns(:custom_link)).to eq(custom_link) |
41 | 41 | end |
42 | 42 |
|
43 | | - it 'authorizes the action' do |
44 | | - expect_any_instance_of(CustomLinkPolicy).to receive(:edit?).and_return(true) |
| 43 | + it "authorizes the action" do |
| 44 | + allow_any_instance_of(CustomLinkPolicy).to receive(:edit?).and_return(true) |
45 | 45 | get edit_custom_link_path(custom_link) |
46 | 46 | end |
47 | 47 | end |
48 | 48 |
|
49 | | - describe 'POST #create' do |
50 | | - context 'with valid parameters' do |
51 | | - it 'creates a new CustomLink' do |
| 49 | + describe "POST #create" do |
| 50 | + context "with valid parameters" do |
| 51 | + it "creates a new CustomLink" do |
52 | 52 | expect do |
53 | | - post custom_links_path, params: { custom_link: valid_attributes } |
| 53 | + post custom_links_path, params: {custom_link: valid_attributes} |
54 | 54 | end.to change(CustomLink, :count).by(1) |
55 | 55 | end |
56 | 56 |
|
57 | | - it 'redirects to the edit_casa_org_path' do |
58 | | - post custom_links_path, params: { custom_link: valid_attributes } |
| 57 | + it "redirects to the edit_casa_org_path" do |
| 58 | + post custom_links_path, params: {custom_link: valid_attributes} |
59 | 59 | expect(response).to redirect_to(edit_casa_org_path(user.casa_org)) |
60 | 60 | end |
61 | 61 |
|
62 | | - it 'sets a success notice' do |
63 | | - post custom_links_path, params: { custom_link: valid_attributes } |
64 | | - expect(flash[:notice]).to eq('Custom link was successfully created.') |
| 62 | + it "sets a success notice" do |
| 63 | + post custom_links_path, params: {custom_link: valid_attributes} |
| 64 | + expect(flash[:notice]).to eq("Custom link was successfully created.") |
65 | 65 | end |
66 | 66 |
|
67 | | - it 'authorizes the action' do |
68 | | - expect_any_instance_of(CustomLinkPolicy).to receive(:create?).and_return(true) |
69 | | - post custom_links_path, params: { custom_link: valid_attributes } |
| 67 | + it "authorizes the action" do |
| 68 | + allow_any_instance_of(CustomLinkPolicy).to receive(:create?).and_return(true) |
| 69 | + post custom_links_path, params: {custom_link: valid_attributes} |
70 | 70 | end |
71 | 71 | end |
72 | 72 |
|
73 | | - context 'with invalid parameters' do |
74 | | - it 'does not create a new CustomLink' do |
| 73 | + context "with invalid parameters" do |
| 74 | + it "does not create a new CustomLink" do |
75 | 75 | expect do |
76 | | - post custom_links_path, params: { custom_link: invalid_attributes } |
77 | | - end.to change(CustomLink, :count).by(0) |
| 76 | + post custom_links_path, params: {custom_link: invalid_attributes} |
| 77 | + end.not_to change(CustomLink, :count) |
78 | 78 | end |
79 | 79 |
|
80 | | - it 'renders the new template' do |
81 | | - post custom_links_path, params: { custom_link: invalid_attributes } |
| 80 | + it "renders the new template" do |
| 81 | + post custom_links_path, params: {custom_link: invalid_attributes} |
82 | 82 | expect(response).to render_template(:new) |
83 | 83 | end |
84 | 84 | end |
85 | 85 | end |
86 | 86 |
|
87 | | - describe 'PATCH/PUT #update' do |
88 | | - context 'with valid parameters' do |
89 | | - let(:new_attributes) { { text: 'Updated Text', url: 'http://updated.com' } } |
| 87 | + describe "PATCH/PUT #update" do |
| 88 | + context "with valid parameters" do |
| 89 | + let(:new_attributes) { {text: "Updated Text", url: "http://updated.com"} } |
90 | 90 |
|
91 | | - it 'updates the requested custom_link' do |
92 | | - patch custom_link_path(custom_link), params: { custom_link: new_attributes } |
| 91 | + it "updates the requested custom_link" do |
| 92 | + patch custom_link_path(custom_link), params: {custom_link: new_attributes} |
93 | 93 | custom_link.reload |
94 | | - expect(custom_link.text).to eq('Updated Text') |
| 94 | + expect(custom_link.text).to eq("Updated Text") |
95 | 95 | end |
96 | 96 |
|
97 | | - it 'redirects to the edit_casa_org_path' do |
98 | | - patch custom_link_path(custom_link), params: { custom_link: new_attributes } |
| 97 | + it "redirects to the edit_casa_org_path" do |
| 98 | + patch custom_link_path(custom_link), params: {custom_link: new_attributes} |
99 | 99 | expect(response).to redirect_to(edit_casa_org_path(user.casa_org)) |
100 | 100 | end |
101 | 101 |
|
102 | | - it 'sets a success notice' do |
103 | | - patch custom_link_path(custom_link), params: { custom_link: new_attributes } |
104 | | - expect(flash[:notice]).to eq('Custom link was successfully updated.') |
| 102 | + it "sets a success notice" do |
| 103 | + patch custom_link_path(custom_link), params: {custom_link: new_attributes} |
| 104 | + expect(flash[:notice]).to eq("Custom link was successfully updated.") |
105 | 105 | end |
106 | 106 |
|
107 | | - it 'authorizes the action' do |
108 | | - expect_any_instance_of(CustomLinkPolicy).to receive(:update?).and_return(true) |
109 | | - patch custom_link_path(custom_link), params: { custom_link: new_attributes } |
| 107 | + it "authorizes the action" do |
| 108 | + allow_any_instance_of(CustomLinkPolicy).to receive(:update?).and_return(true) |
| 109 | + patch custom_link_path(custom_link), params: {custom_link: new_attributes} |
110 | 110 | end |
111 | 111 | end |
112 | 112 |
|
113 | | - context 'with invalid parameters' do |
114 | | - it 'does not update the requested custom_link' do |
115 | | - patch custom_link_path(custom_link), params: { custom_link: invalid_attributes } |
| 113 | + context "with invalid parameters" do |
| 114 | + it "does not update the requested custom_link" do |
| 115 | + patch custom_link_path(custom_link), params: {custom_link: invalid_attributes} |
116 | 116 | custom_link.reload |
117 | 117 | expect(custom_link.text).not_to be_empty |
118 | 118 | end |
119 | 119 |
|
120 | | - it 'renders the edit template' do |
121 | | - patch custom_link_path(custom_link), params: { custom_link: invalid_attributes } |
| 120 | + it "renders the edit template" do |
| 121 | + patch custom_link_path(custom_link), params: {custom_link: invalid_attributes} |
122 | 122 | expect(response).to render_template(:edit) |
123 | 123 | end |
124 | 124 | end |
125 | 125 | end |
126 | 126 |
|
127 | | - describe 'DELETE #destroy' do |
128 | | - it 'destroys the requested custom_link' do |
| 127 | + describe "DELETE #destroy" do |
| 128 | + it "destroys the requested custom_link" do |
129 | 129 | custom_link |
130 | 130 | expect do |
131 | 131 | delete custom_link_path(custom_link) |
132 | 132 | end.to change(CustomLink, :count).by(-1) |
133 | 133 | end |
134 | 134 |
|
135 | | - it 'redirects to the edit_casa_org_path' do |
| 135 | + it "redirects to the edit_casa_org_path" do |
136 | 136 | delete custom_link_path(custom_link) |
137 | 137 | expect(response).to redirect_to(edit_casa_org_path(user.casa_org)) |
138 | 138 | end |
139 | 139 |
|
140 | | - it 'sets a success notice' do |
| 140 | + it "sets a success notice" do |
141 | 141 | delete custom_link_path(custom_link) |
142 | | - expect(flash[:notice]).to eq('Custom link was successfully removed.') |
| 142 | + expect(flash[:notice]).to eq("Custom link was successfully removed.") |
143 | 143 | end |
144 | 144 |
|
145 | | - it 'authorizes the action' do |
146 | | - expect_any_instance_of(CustomLinkPolicy).to receive(:destroy?).and_return(true) |
| 145 | + it "authorizes the action" do |
| 146 | + allow_any_instance_of(CustomLinkPolicy).to receive(:destroy?).and_return(true) |
147 | 147 | delete custom_link_path(custom_link) |
148 | 148 | end |
149 | 149 | end |
|
0 commit comments