|
89 | 89 | end |
90 | 90 | end |
91 | 91 |
|
| 92 | + describe "GET /learnings/:id/edit" do |
| 93 | + it "returns http success" do |
| 94 | + get edit_learning_path(learning1) |
| 95 | + expect(response).to have_http_status(:success) |
| 96 | + expect(response.body).to include("Edit Learning") |
| 97 | + expect(response.body).to include(learning1.title) |
| 98 | + end |
| 99 | + end |
| 100 | + |
| 101 | + describe "PATCH /learnings/:id" do |
| 102 | + context "with valid parameters" do |
| 103 | + let(:new_attributes) { |
| 104 | + { title: "Updated Ruby Basics", body: "Updated body", tags: "ruby, updated", learned_on: Date.today - 3.days } |
| 105 | + } |
| 106 | + |
| 107 | + it "updates the requested learning" do |
| 108 | + patch learning_path(learning1), params: { learning: new_attributes } |
| 109 | + learning1.reload |
| 110 | + expect(learning1.title).to eq("Updated Ruby Basics") |
| 111 | + expect(learning1.body).to eq("Updated body") |
| 112 | + expect(learning1.tags).to eq("ruby, updated") |
| 113 | + expect(learning1.learned_on).to eq(Date.today - 3.days) |
| 114 | + end |
| 115 | + |
| 116 | + it "redirects to the learnings index" do |
| 117 | + patch learning_path(learning1), params: { learning: new_attributes } |
| 118 | + expect(response).to redirect_to(learnings_path) |
| 119 | + expect(flash[:notice]).to eq("Learning updated successfully.") |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + context "with invalid parameters" do |
| 124 | + let(:invalid_attributes) { { title: "", body: "" } } # Invalid: missing title and body |
| 125 | + |
| 126 | + it "does not update the learning" do |
| 127 | + original_title = learning1.title |
| 128 | + patch learning_path(learning1), params: { learning: invalid_attributes } |
| 129 | + learning1.reload |
| 130 | + expect(learning1.title).to eq(original_title) |
| 131 | + end |
| 132 | + |
| 133 | + it "re-renders the 'edit' template" do |
| 134 | + patch learning_path(learning1), params: { learning: invalid_attributes } |
| 135 | + expect(response).to have_http_status(:unprocessable_entity) |
| 136 | + expect(response).to render_template(:edit) |
| 137 | + end |
| 138 | + end |
| 139 | + end |
| 140 | + |
92 | 141 | describe "DELETE /learnings/multiple" do |
93 | 142 | it "deletes the selected learnings" do |
94 | 143 | learnings_to_delete = [ learning1, learning3 ] |
|
0 commit comments