测试scope
describe 'scope' do
describe '.recommendations' do
before(:each) do
course.recommend = true
course.save!
end
it { expect(Course.recommendations.count).to be(1)}
end
describe 'hotness' do
let(:user) { create :user}
let(:course) { create :course}
before(:each) do
learning = CourseLearning.new
user.enroll(course, learning)
end
it { expect(course.learning_count).to be(1)}
it 'return 0' do
user.cancel_enroll(course)
expect(Course.find(course.id).learning_count).to eq(0)
end
it 'return 2' do
user_2 = create :user
learning = CourseLearning.new
user_2.enroll(course, learning)
expect(course.learning_count).to be(2)
end
end
end