ambition/spec/controllers/projects_controller_spec.rb

83 lines
2.4 KiB
Ruby
Raw Normal View History

2017-01-01 17:00:27 +08:00
require 'rails_helper'
RSpec.describe ProjectsController, type: :controller do
describe "GET #index " do
it "return valid projects json" do
register = create(:user)
user = User.find_by(email: register.email)
session[:user_id] = user.id
post :create,content: "project content 1",name: "project1"
post :create,content: "project content 2", name: "project2"
get :index
puts response.body
end
end
describe "POST #create" do
it "can create a valid project" do
register = create(:user)
user = User.find_by(email: register.email)
#puts user.inspect
session[:user_id] = user.id
post :create,content: "project content 1",name: "project1"
#puts response.body
end
end
describe "POST #addUsers" do
it "can addUsers correctly" do
register = create(:user)
user = User.find_by(email: register.email)
session[:user_id] = user.id
#user1 = create(:user)
user2 = create(:user)
params = {name: "project addUsers test",content: "addUsers test"}
project = Project.new(params)
project.users << register
project.save
#post :create,content: "project content 3",name: "project3"
post :addUsers,user_id: user2.id,project_id: project.id
end
end
describe "GET #detail" do
it "can return correct json format of project " do
register = create(:user)
user = User.find_by(email: register.email)
session[:user_id] = user.id
user1 = create(:user)
user2 = create(:user)
params = {name: "project addUsers test",content: "addUsers test"}
project = Project.new(params)
project.users << register
project.save
post :addUsers,user_id: user2.id,project_id: project.id
post :addUsers,user_id: user1.id,project_id: project.id
post :detail,id: project.id
puts response.body
end
end
end