2015-05-15 13:39:26 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'shared_account_spec'
|
|
|
|
|
|
|
|
RSpec.describe "课程", :type => :request do
|
|
|
|
let(:course){FactoryGirl.attributes_for(:course)}
|
|
|
|
describe "创建课程" do
|
|
|
|
include_context "create user"
|
|
|
|
before {
|
|
|
|
shared_register
|
|
|
|
shared_update_user
|
|
|
|
}
|
|
|
|
context "参数正确,成功创建课程" do
|
|
|
|
before{
|
2015-05-15 16:18:44 +08:00
|
|
|
# uu = current_user
|
|
|
|
# allow(User).to receive(:current).and_return(uu)
|
|
|
|
# allow(uu).to receive(:allowed_to?).and_return(123)
|
2015-05-15 13:39:26 +08:00
|
|
|
post courses_path,
|
|
|
|
"course[name]"=> course[:name],
|
2015-05-15 16:18:44 +08:00
|
|
|
"class_period"=> course[:class_period],
|
2015-05-15 13:39:26 +08:00
|
|
|
"time"=> course[:time],
|
|
|
|
"term"=> course[:term],
|
|
|
|
"course[password]"=>course[:password],
|
|
|
|
"course[description]"=> course[:description],
|
|
|
|
"course[is_public]"=> course[:is_public],
|
|
|
|
"course[open_student]"=> course[:open_student]
|
|
|
|
}
|
2015-05-15 16:18:44 +08:00
|
|
|
it{expect(assigns(:course)).to be_instance_of(Course)}
|
|
|
|
it{expect(response).to redirect_to(settings_course_url(assigns(:course), course_type: 1))}
|
2015-05-15 13:39:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "配置课程" do
|
2015-05-15 16:18:44 +08:00
|
|
|
let (:course) {FactoryGirl.create(:course)}
|
|
|
|
|
2015-05-15 13:39:26 +08:00
|
|
|
context "修改课程图片" do
|
2015-05-15 16:18:44 +08:00
|
|
|
include Rack::Test::Methods
|
|
|
|
let(:avatar) {Rack::Test::UploadedFile.new("#{Rails.root}/spec/fixtures/test.jpg",'image/jpg')}
|
|
|
|
context "正常图片上传成功" do
|
|
|
|
subject(:resp) {post upload_avatar_path(source_type: 'Course', source_id: course.id, format: :json),"avatar"=>{image: avatar}}
|
|
|
|
it{ expect(subject).to be_ok }
|
|
|
|
it{ expect(subject.body).not_to be_empty }
|
2015-05-15 13:39:26 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "不是图片,上传失败"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|