150 lines
5.4 KiB
Ruby
150 lines
5.4 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe MissionsController, type: :controller do
|
|
|
|
describe "GET #getlist" do
|
|
|
|
it "return a valid json format of missions" do
|
|
|
|
register = create(:user)
|
|
user = User.find_by(email: register.email)
|
|
session[:user_id] = user.id
|
|
|
|
params = {name: "project addUsers test",content: "addUsers test"}
|
|
project = Project.new(params)
|
|
project.users << register
|
|
project.save
|
|
|
|
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
|
params_mission2 = {name: "mission2",content: "mission content2",deadline:"2016-10-17 10:00:00",priority:1,status:2,project_id: project.id}
|
|
mission = Mission.new(params_mission)
|
|
mission2 = Mission.new(params_mission2)
|
|
mission.save
|
|
mission2.save
|
|
get :getlist,project_id: project.id,status_type: 1
|
|
|
|
puts response.body
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
describe "GET #detail" do
|
|
|
|
it "return a correct json format detail" do
|
|
|
|
register = create(:user)
|
|
session[:user_id] = register.id
|
|
params = {name: "project addUsers test",content: "addUsers test"}
|
|
project = Project.new(params)
|
|
project.users << register
|
|
project.save
|
|
|
|
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
|
#params_mission2 = {name: "mission2",content: "mission content2",deadline:"2016-10-17 10:00:00",priority:1,status:2,project_id: project.id}
|
|
mission = Mission.new(params_mission)
|
|
mission.save
|
|
|
|
post :commentPublish,content: "评论1",mission_id: mission.id
|
|
post :commentPublish,content: "评论2",mission_id: mission.id
|
|
|
|
get :detail,id: mission.id
|
|
|
|
puts response.body
|
|
end
|
|
|
|
end
|
|
|
|
describe "POST #comments" do
|
|
|
|
it "can publish comments successfully" do
|
|
|
|
|
|
register = create(:user)
|
|
params = {name: "project addUsers test",content: "addUsers test"}
|
|
session[:user_id] = register.id
|
|
project = Project.new(params)
|
|
project.users << register
|
|
project.save
|
|
|
|
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
|
mission = Mission.new(params_mission)
|
|
mission.save
|
|
|
|
post :commentPublish,mission_id: mission.id,content: "asda"
|
|
|
|
puts response.body
|
|
end
|
|
|
|
end
|
|
|
|
|
|
describe "POST #update" do
|
|
|
|
it "can update missions successfully" do
|
|
|
|
register = create(:user)
|
|
user = User.find_by(email: register.email)
|
|
session[:user_id] = user.id
|
|
|
|
params = {name: "project mission update test",content: "update test"}
|
|
project = Project.new(params)
|
|
project.users << register
|
|
project.save
|
|
|
|
user1 = create(:user,name: "yangzhao")
|
|
user2 = create(:user,name: "chenyi")
|
|
|
|
user3 = create(:user,name: "yangzhao")
|
|
user4 = create(:user,name: "chenyi")
|
|
|
|
puts user1.inspect
|
|
params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
|
mission = Mission.new(params_mission)
|
|
mission.save
|
|
|
|
post :create,project_id: project.id,name: "前端原型开发",content:"开发出前端原型",priority:1,status:1,deadline:"2017-01-02 14:14:54",users: [user1.name,user2.name]
|
|
|
|
patch :update,name: "前端原型开发",id: mission.id,content:"完善前端原型",priority:1,status:1,deadline:"2017-01-03 14:14:54",users: [user3.name,user4.name]
|
|
|
|
post :detail,id: 1
|
|
puts response.body
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
describe "POST #create" do
|
|
|
|
it "can create missions successfully" do
|
|
|
|
register = create(:user)
|
|
user = User.find_by(email: register.email)
|
|
session[:user_id] = user.id
|
|
|
|
params = {name: "project mission update test",content: "update test"}
|
|
project = Project.new(params)
|
|
project.users << register
|
|
project.save
|
|
|
|
user1 = create(:user)
|
|
user2 = create(:user)
|
|
project.users << user1
|
|
project.users << user2
|
|
#params_mission = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:1,project_id: project.id}
|
|
|
|
post :create,project_id: project.id,name: "前端原型开发",content:"开发出前端原型",priority:1,status:1,deadline:"2017-01-02 10:00:00",users: [user1.name,user2.name]
|
|
|
|
post :detail,id: 1
|
|
|
|
puts response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
end |