socialforge/spec/requests/homework_request_spec.rb

53 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

2016-03-11 10:18:10 +08:00
require 'rails_helper'
require 'shared_account_spec'
RSpec.describe "homework", type: :request do
include_context "create user"
let(:course) {FactoryGirl.create(:course, teacher: current_user)}
let(:homework){FactoryGirl.attributes_for(:homework)}
before {
shared_register
}
describe "创建作业" do
before do
post calls_create_homework_path(course_id: course.id), {
bid: homework
}
@homework = assigns(:bid)
end
it "参数正确,可以成功创建作业" do
expect(response).to redirect_to(course_homework_url(course.id))
end
it {expect(course.homeworks).to_not be_empty}
it {expect(@homework.acts).to_not be_empty}
it {expect(@homework.watchers).to_not be_empty}
it {expect(@homework.attachments).to_not be_empty}
end
describe "删除作业" do
before do
shared_login
post calls_create_homework_path(course_id: course.id), {
bid: homework
}
@homework = assigns(:bid)
delete bids_homework_path(id: @homework.id)
end
it{expect(response).to redirect_to(course_homework_path(course.id))}
it "homework_for_courses应删除" do
expect(course.homeworks).to be_empty
end
it "相关活动也删除" do
expect(@homework.acts).to be_empty
end
it "watches 删除" do
expect(@homework.watchers).to be_empty
end
it "附件 删除" do
expect(@homework.attachments).to be_empty
end
end
end