|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +class ProjectsTest < ActionDispatch::IntegrationTest |
| 4 | + test "create" do |
| 5 | + before = Project.all.size |
| 6 | + Dir.mktmpdir do |tmpdir| |
| 7 | + params = { |
| 8 | + project: { |
| 9 | + name: "test project one", |
| 10 | + description: "test project one description", |
| 11 | + directory: tmpdir |
| 12 | + } |
| 13 | + } |
| 14 | + post projects_path, params: params |
| 15 | + follow_redirect! |
| 16 | + assert_response :success |
| 17 | + |
| 18 | + get projects_path |
| 19 | + assert_response :success |
| 20 | + |
| 21 | + after = Project.all.size |
| 22 | + assert after == before + 1 |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + test "deleting_a_project" do |
| 27 | + before = Project.all.size |
| 28 | + Dir.mktmpdir do |tmpdir| |
| 29 | + params = { |
| 30 | + project: { |
| 31 | + name: "test project one", |
| 32 | + description: "test project one description", |
| 33 | + directory: tmpdir |
| 34 | + } |
| 35 | + } |
| 36 | + post projects_path, params: params |
| 37 | + |
| 38 | + id = @response.location.to_s.split("/").last |
| 39 | + |
| 40 | + delete project_path(id) |
| 41 | + follow_redirect! |
| 42 | + assert_response :success |
| 43 | + |
| 44 | + after = Project.all.size |
| 45 | + assert after = before -1 |
| 46 | + end |
| 47 | + end |
| 48 | + test "update a project" do |
| 49 | + Dir.mktmpdir do |tmpdir2| |
| 50 | + Dir.mktmpdir do |tmpdir| |
| 51 | + params = { |
| 52 | + project: { |
| 53 | + name: "update project", |
| 54 | + desccription: "project description", |
| 55 | + directory: tmpdir |
| 56 | + } |
| 57 | + } |
| 58 | + new_params = { |
| 59 | + project: { |
| 60 | + name: "new name", |
| 61 | + desccription: "new description", |
| 62 | + directory: tmpdir2 |
| 63 | + } |
| 64 | + } |
| 65 | + post projects_path, params: params |
| 66 | + |
| 67 | + id = @response.location.to_s.split("/").last |
| 68 | + |
| 69 | + get edit_project_path(id) |
| 70 | + assert_response :success |
| 71 | + |
| 72 | + before = Project.all.size |
| 73 | + |
| 74 | + put project_path(id), params: new_params |
| 75 | + follow_redirect! |
| 76 | + assert_response :success |
| 77 | + |
| 78 | + after = Project.all.size |
| 79 | + assert_equal(before, after) |
| 80 | + end |
| 81 | + end |
| 82 | + end |
| 83 | +end |
0 commit comments