rename factory_girl_(rails) to factory_bot_(rails)

This commit is contained in:
Ralf Teusner
2017-11-15 15:18:07 +01:00
parent 951b71780c
commit 0e26ab98c8
68 changed files with 253 additions and 253 deletions

View File

@ -1,7 +1,7 @@
require 'rails_helper'
describe Admin::DashboardController do
before(:each) { allow(controller).to receive(:current_user).and_return(FactoryGirl.build(:admin)) }
before(:each) { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:admin)) }
describe 'GET #show' do
describe 'with format HTML' do

View File

@ -3,7 +3,7 @@ require 'rails_helper'
describe ApplicationController do
describe '#current_user' do
context 'with an external user' do
let(:external_user) { FactoryGirl.create(:external_user) }
let(:external_user) { FactoryBot.create(:external_user) }
before(:each) { session[:external_user_id] = external_user.id }
it 'returns the external user' do
@ -12,7 +12,7 @@ describe ApplicationController do
end
context 'without an external user' do
let(:internal_user) { FactoryGirl.create(:teacher) }
let(:internal_user) { FactoryBot.create(:teacher) }
before(:each) { login_user(internal_user) }
it 'returns the internal user' do

View File

@ -1,14 +1,14 @@
require 'rails_helper'
describe CodeOcean::FilesController do
let(:user) { FactoryGirl.create(:admin) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
let(:submission) { FactoryGirl.create(:submission, user: user) }
let(:submission) { FactoryBot.create(:submission, user: user) }
context 'with a valid file' do
let(:request) { proc { post :create, code_ocean_file: FactoryGirl.build(:file, context: submission).attributes, format: :json } }
let(:request) { proc { post :create, code_ocean_file: FactoryBot.build(:file, context: submission).attributes, format: :json } }
before(:each) { request.call }
expect_assigns(file: CodeOcean::File)
@ -31,14 +31,14 @@ describe CodeOcean::FilesController do
end
describe 'DELETE #destroy' do
let(:exercise) { FactoryGirl.create(:fibonacci) }
let(:exercise) { FactoryBot.create(:fibonacci) }
let(:request) { proc { delete :destroy, id: exercise.files.first.id } }
before(:each) { request.call }
expect_assigns(file: CodeOcean::File)
it 'destroys the file' do
FactoryGirl.create(:fibonacci)
FactoryBot.create(:fibonacci)
expect { request.call }.to change(CodeOcean::File, :count).by(-1)
end

View File

@ -1,13 +1,13 @@
require 'rails_helper'
describe ConsumersController do
let(:consumer) { FactoryGirl.create(:consumer) }
let(:user) { FactoryGirl.create(:admin) }
let(:consumer) { FactoryBot.create(:consumer) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
context 'with a valid consumer' do
let(:request) { proc { post :create, consumer: FactoryGirl.attributes_for(:consumer) } }
let(:request) { proc { post :create, consumer: FactoryBot.attributes_for(:consumer) } }
before(:each) { request.call }
expect_assigns(consumer: Consumer)
@ -34,7 +34,7 @@ describe ConsumersController do
expect_assigns(consumer: Consumer)
it 'destroys the consumer' do
consumer = FactoryGirl.create(:consumer)
consumer = FactoryBot.create(:consumer)
expect { delete :destroy, id: consumer.id }.to change(Consumer, :count).by(-1)
end
@ -50,7 +50,7 @@ describe ConsumersController do
end
describe 'GET #index' do
let!(:consumers) { FactoryGirl.create_pair(:consumer) }
let!(:consumers) { FactoryBot.create_pair(:consumer) }
before(:each) { get :index }
expect_assigns(consumers: Consumer.all)
@ -76,7 +76,7 @@ describe ConsumersController do
describe 'PUT #update' do
context 'with a valid consumer' do
before(:each) { put :update, consumer: FactoryGirl.attributes_for(:consumer), id: consumer.id }
before(:each) { put :update, consumer: FactoryBot.attributes_for(:consumer), id: consumer.id }
expect_assigns(consumer: Consumer)
expect_redirect(:consumer)

View File

@ -1,15 +1,15 @@
require 'rails_helper'
describe ExecutionEnvironmentsController do
let(:execution_environment) { FactoryGirl.create(:ruby) }
let(:user) { FactoryGirl.create(:admin) }
let(:execution_environment) { FactoryBot.create(:ruby) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
before(:each) { expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([]) }
context 'with a valid execution environment' do
let(:request) { proc { post :create, execution_environment: FactoryGirl.attributes_for(:ruby) } }
let(:request) { proc { post :create, execution_environment: FactoryBot.attributes_for(:ruby) } }
before(:each) { request.call }
expect_assigns(docker_images: Array)
@ -37,7 +37,7 @@ describe ExecutionEnvironmentsController do
expect_assigns(execution_environment: :execution_environment)
it 'destroys the execution environment' do
execution_environment = FactoryGirl.create(:ruby)
execution_environment = FactoryBot.create(:ruby)
expect { delete :destroy, id: execution_environment.id }.to change(ExecutionEnvironment, :count).by(-1)
end
@ -72,7 +72,7 @@ describe ExecutionEnvironmentsController do
end
describe 'GET #index' do
before(:all) { FactoryGirl.create_pair(:ruby) }
before(:all) { FactoryBot.create_pair(:ruby) }
before(:each) { get :index }
expect_assigns(execution_environments: ExecutionEnvironment.all)
@ -150,7 +150,7 @@ describe ExecutionEnvironmentsController do
context 'with a valid execution environment' do
before(:each) do
expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([])
put :update, execution_environment: FactoryGirl.attributes_for(:ruby), id: execution_environment.id
put :update, execution_environment: FactoryBot.attributes_for(:ruby), id: execution_environment.id
end
expect_assigns(docker_images: Array)

View File

@ -1,8 +1,8 @@
require 'rails_helper'
describe ExercisesController do
let(:exercise) { FactoryGirl.create(:dummy) }
let(:user) { FactoryGirl.create(:admin) }
let(:exercise) { FactoryBot.create(:dummy) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'PUT #batch_update' do
@ -52,7 +52,7 @@ describe ExercisesController do
end
describe 'POST #create' do
let(:exercise_attributes) { FactoryGirl.build(:dummy).attributes }
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
context 'with a valid exercise' do
let(:request) { proc { post :create, exercise: exercise_attributes } }
@ -71,7 +71,7 @@ describe ExercisesController do
let(:request) { proc { post :create, exercise: exercise_attributes.merge(files_attributes: files_attributes) } }
context 'when specifying the file content within the form' do
let(:files_attributes) { {'0' => FactoryGirl.build(:file).attributes} }
let(:files_attributes) { {'0' => FactoryBot.build(:file).attributes} }
it 'creates the file' do
expect { request.call }.to change(CodeOcean::File, :count)
@ -79,11 +79,11 @@ describe ExercisesController do
end
context 'when uploading a file' do
let(:files_attributes) { {'0' => FactoryGirl.build(:file, file_type: file_type).attributes.merge(content: uploaded_file)} }
let(:files_attributes) { {'0' => FactoryBot.build(:file, file_type: file_type).attributes.merge(content: uploaded_file)} }
context 'when uploading a binary file' do
let(:file_path) { Rails.root.join('db', 'seeds', 'audio_video', 'devstories.mp4') }
let(:file_type) { FactoryGirl.create(:dot_mp4) }
let(:file_type) { FactoryBot.create(:dot_mp4) }
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'video/mp4', true) }
it 'creates the file' do
@ -98,7 +98,7 @@ describe ExercisesController do
context 'when uploading a non-binary file' do
let(:file_path) { Rails.root.join('db', 'seeds', 'fibonacci', 'exercise.rb') }
let(:file_type) { FactoryGirl.create(:dot_rb) }
let(:file_type) { FactoryBot.create(:dot_rb) }
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'text/x-ruby', false) }
it 'creates the file' do
@ -128,7 +128,7 @@ describe ExercisesController do
expect_assigns(exercise: :exercise)
it 'destroys the exercise' do
exercise = FactoryGirl.create(:dummy)
exercise = FactoryBot.create(:dummy)
expect { delete :destroy, id: exercise.id }.to change(Exercise, :count).by(-1)
end
@ -147,13 +147,13 @@ describe ExercisesController do
let(:request) { proc { get :implement, id: exercise.id } }
context 'with an exercise with visible files' do
let(:exercise) { FactoryGirl.create(:fibonacci) }
let(:exercise) { FactoryBot.create(:fibonacci) }
before(:each) { request.call }
expect_assigns(exercise: :exercise)
context 'with an existing submission' do
let!(:submission) { FactoryGirl.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
let!(:submission) { FactoryBot.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
it "populates the editors with the submission's files' content" do
request.call
@ -182,7 +182,7 @@ describe ExercisesController do
describe 'GET #index' do
let(:scope) { Pundit.policy_scope!(user, Exercise) }
before(:all) { FactoryGirl.create_pair(:dummy) }
before(:all) { FactoryBot.create_pair(:dummy) }
before(:each) { get :index }
expect_assigns(exercises: :scope)
@ -230,8 +230,8 @@ describe ExercisesController do
describe 'POST #submit' do
let(:output) { {} }
let(:request) { post :submit, format: :json, id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id} }
let!(:external_user) { FactoryGirl.create(:external_user) }
let!(:lti_parameter) { FactoryGirl.create(:lti_parameter, external_user: external_user, exercise: exercise) }
let!(:external_user) { FactoryBot.create(:external_user) }
let!(:lti_parameter) { FactoryBot.create(:lti_parameter, external_user: external_user, exercise: exercise) }
before(:each) do
allow_any_instance_of(Submission).to receive(:normalized_score).and_return(1)
@ -298,7 +298,7 @@ describe ExercisesController do
describe 'PUT #update' do
context 'with a valid exercise' do
let(:exercise_attributes) { FactoryGirl.build(:dummy).attributes }
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
before(:each) { put :update, exercise: exercise_attributes, id: exercise.id }
expect_assigns(exercise: Exercise)

View File

@ -1,8 +1,8 @@
require 'rails_helper'
describe ExternalUsersController do
let(:user) { FactoryGirl.build(:admin) }
let!(:users) { FactoryGirl.create_pair(:external_user) }
let(:user) { FactoryBot.build(:admin) }
let!(:users) { FactoryBot.create_pair(:external_user) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'GET #index' do

View File

@ -1,13 +1,13 @@
require 'rails_helper'
describe FileTypesController do
let(:file_type) { FactoryGirl.create(:dot_rb) }
let(:user) { FactoryGirl.create(:admin) }
let(:file_type) { FactoryBot.create(:dot_rb) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
context 'with a valid file type' do
let(:request) { proc { post :create, file_type: FactoryGirl.attributes_for(:dot_rb) } }
let(:request) { proc { post :create, file_type: FactoryBot.attributes_for(:dot_rb) } }
before(:each) { request.call }
expect_assigns(editor_modes: Array)
@ -36,7 +36,7 @@ describe FileTypesController do
expect_assigns(file_type: FileType)
it 'destroys the file type' do
file_type = FactoryGirl.create(:dot_rb)
file_type = FactoryBot.create(:dot_rb)
expect { delete :destroy, id: file_type.id }.to change(FileType, :count).by(-1)
end
@ -53,7 +53,7 @@ describe FileTypesController do
end
describe 'GET #index' do
before(:all) { FactoryGirl.create_pair(:dot_rb) }
before(:all) { FactoryBot.create_pair(:dot_rb) }
before(:each) { get :index }
expect_assigns(file_types: FileType.all)
@ -80,7 +80,7 @@ describe FileTypesController do
describe 'PUT #update' do
context 'with a valid file type' do
before(:each) { put :update, file_type: FactoryGirl.attributes_for(:dot_rb), id: file_type.id }
before(:each) { put :update, file_type: FactoryBot.attributes_for(:dot_rb), id: file_type.id }
expect_assigns(editor_modes: Array)
expect_assigns(file_type: FileType)

View File

@ -1,14 +1,14 @@
require 'rails_helper'
describe HintsController do
let(:execution_environment) { FactoryGirl.create(:ruby) }
let(:hint) { FactoryGirl.create(:ruby_syntax_error) }
let(:user) { FactoryGirl.create(:admin) }
let(:execution_environment) { FactoryBot.create(:ruby) }
let(:hint) { FactoryBot.create(:ruby_syntax_error) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
context 'with a valid hint' do
let(:request) { proc { post :create, execution_environment_id: execution_environment.id, hint: FactoryGirl.attributes_for(:ruby_syntax_error) } }
let(:request) { proc { post :create, execution_environment_id: execution_environment.id, hint: FactoryBot.attributes_for(:ruby_syntax_error) } }
before(:each) { request.call }
expect_assigns(execution_environment: :execution_environment)
@ -38,7 +38,7 @@ describe HintsController do
expect_assigns(hint: Hint)
it 'destroys the hint' do
hint = FactoryGirl.create(:ruby_syntax_error)
hint = FactoryBot.create(:ruby_syntax_error)
expect { delete :destroy, execution_environment_id: execution_environment.id, id: hint.id }.to change(Hint, :count).by(-1)
end
@ -55,7 +55,7 @@ describe HintsController do
end
describe 'GET #index' do
before(:all) { FactoryGirl.create_pair(:ruby_syntax_error) }
before(:all) { FactoryBot.create_pair(:ruby_syntax_error) }
before(:each) { get :index, execution_environment_id: execution_environment.id }
expect_assigns(execution_environment: :execution_environment)
@ -84,7 +84,7 @@ describe HintsController do
describe 'PUT #update' do
context 'with a valid hint' do
before(:each) { put :update, execution_environment_id: execution_environment.id, hint: FactoryGirl.attributes_for(:ruby_syntax_error), id: hint.id }
before(:each) { put :update, execution_environment_id: execution_environment.id, hint: FactoryBot.attributes_for(:ruby_syntax_error), id: hint.id }
expect_assigns(execution_environment: :execution_environment)
expect_assigns(hint: Hint)

View File

@ -1,11 +1,11 @@
require 'rails_helper'
describe InternalUsersController do
let(:user) { FactoryGirl.build(:admin) }
let!(:users) { FactoryGirl.create_pair(:teacher) }
let(:user) { FactoryBot.build(:admin) }
let!(:users) { FactoryBot.create_pair(:teacher) }
describe 'GET #activate' do
let(:user) { InternalUser.create(FactoryGirl.attributes_for(:teacher)) }
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
before(:each) do
user.send(:setup_activation)
@ -37,7 +37,7 @@ describe InternalUsersController do
end
describe 'PUT #activate' do
let(:user) { InternalUser.create(FactoryGirl.attributes_for(:teacher)) }
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
let(:password) { SecureRandom.hex }
before(:each) do
@ -103,7 +103,7 @@ describe InternalUsersController do
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
context 'with a valid internal user' do
let(:request) { proc { post :create, internal_user: FactoryGirl.attributes_for(:teacher) } }
let(:request) { proc { post :create, internal_user: FactoryBot.attributes_for(:teacher) } }
before(:each) { request.call }
expect_assigns(user: InternalUser)
@ -303,7 +303,7 @@ describe InternalUsersController do
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
context 'with a valid internal user' do
before(:each) { put :update, internal_user: FactoryGirl.attributes_for(:teacher), id: users.first.id }
before(:each) { put :update, internal_user: FactoryBot.attributes_for(:teacher), id: users.first.id }
expect_assigns(user: InternalUser)
expect_redirect { user }

View File

@ -1,12 +1,12 @@
require 'rails_helper'
describe SessionsController do
let(:consumer) { FactoryGirl.create(:consumer) }
let(:consumer) { FactoryBot.create(:consumer) }
describe 'POST #create' do
let(:password) { user_attributes[:password] }
let(:user) { InternalUser.create(user_attributes) }
let(:user_attributes) { FactoryGirl.attributes_for(:teacher) }
let(:user_attributes) { FactoryBot.attributes_for(:teacher) }
context 'with valid credentials' do
before(:each) do
@ -27,8 +27,8 @@ describe SessionsController do
end
describe 'POST #create_through_lti' do
let(:exercise) { FactoryGirl.create(:dummy) }
let(:exercise2) { FactoryGirl.create(:dummy) }
let(:exercise) { FactoryBot.create(:dummy) }
let(:exercise2) { FactoryBot.create(:dummy) }
let(:nonce) { SecureRandom.hex }
before(:each) { I18n.locale = I18n.default_locale }
@ -73,7 +73,7 @@ describe SessionsController do
context 'with valid launch parameters' do
let(:locale) { :de }
let(:request) { post :create_through_lti, custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id }
let(:user) { FactoryGirl.create(:external_user, consumer_id: consumer.id) }
let(:user) { FactoryBot.create(:external_user, consumer_id: consumer.id) }
before(:each) { expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
it 'assigns the current user' do
@ -132,14 +132,14 @@ describe SessionsController do
end
it 'redirects to recommended exercise if requested token of proxy exercise' do
FactoryGirl.create(:proxy_exercise, exercises: [exercise])
FactoryBot.create(:proxy_exercise, exercises: [exercise])
post :create_through_lti, custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id
expect(controller).to redirect_to(implement_exercise_path(exercise.id))
end
it 'recommends only exercises who are 1 degree more complicated than what user has seen' do
# dummy user has no exercises finished, therefore his highest difficulty is 0
FactoryGirl.create(:proxy_exercise, exercises: [exercise, exercise2])
FactoryBot.create(:proxy_exercise, exercises: [exercise, exercise2])
exercise.expected_difficulty = 3
exercise.save
exercise2.expected_difficulty = 1
@ -191,7 +191,7 @@ describe SessionsController do
describe 'GET #destroy_through_lti' do
let(:request) { proc { get :destroy_through_lti, consumer_id: consumer.id, submission_id: submission.id } }
let(:submission) { FactoryGirl.create(:submission, exercise: FactoryGirl.create(:dummy)) }
let(:submission) { FactoryBot.create(:submission, exercise: FactoryGirl.create(:dummy)) }
before(:each) do
#Todo replace session with lti_parameter
@ -225,7 +225,7 @@ describe SessionsController do
context 'when a user is already logged in' do
before(:each) do
expect(controller).to receive(:current_user).and_return(FactoryGirl.build(:teacher))
expect(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher))
get :new
end

View File

@ -1,8 +1,8 @@
require 'rails_helper'
describe SubmissionsController do
let(:submission) { FactoryGirl.create(:submission) }
let(:user) { FactoryGirl.create(:admin) }
let(:submission) { FactoryBot.create(:submission) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
@ -11,8 +11,8 @@ describe SubmissionsController do
end
context 'with a valid submission' do
let(:exercise) { FactoryGirl.create(:hello_world) }
let(:request) { proc { post :create, format: :json, submission: FactoryGirl.attributes_for(:submission, exercise_id: exercise.id) } }
let(:exercise) { FactoryBot.create(:hello_world) }
let(:request) { proc { post :create, format: :json, submission: FactoryBot.attributes_for(:submission, exercise_id: exercise.id) } }
before(:each) { request.call }
expect_assigns(submission: Submission)
@ -42,7 +42,7 @@ describe SubmissionsController do
end
context 'with a valid filename' do
let(:submission) { FactoryGirl.create(:submission, exercise: FactoryGirl.create(:audio_video)) }
let(:submission) { FactoryBot.create(:submission, exercise: FactoryGirl.create(:audio_video)) }
before(:each) { get :download_file, filename: file.name_with_extension, id: submission.id }
context 'for a binary file' do
@ -74,7 +74,7 @@ describe SubmissionsController do
end
describe 'GET #index' do
before(:all) { FactoryGirl.create_pair(:submission) }
before(:all) { FactoryBot.create_pair(:submission) }
before(:each) { get :index }
expect_assigns(submissions: Submission.all)
@ -92,7 +92,7 @@ describe SubmissionsController do
end
context 'with a valid filename' do
let(:submission) { FactoryGirl.create(:submission, exercise: FactoryGirl.create(:audio_video)) }
let(:submission) { FactoryBot.create(:submission, exercise: FactoryGirl.create(:audio_video)) }
before(:each) { get :render_file, filename: file.name_with_extension, id: submission.id }
context 'for a binary file' do