transferred Code Ocean from original repository to GitHub
This commit is contained in:
12
spec/support/anonymous_controller.rb
Normal file
12
spec/support/anonymous_controller.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class AnonymousController < ApplicationController
|
||||
def flash
|
||||
@flash ||= {}
|
||||
end
|
||||
|
||||
def redirect_to(*options)
|
||||
end
|
||||
|
||||
def session
|
||||
@session ||= {}
|
||||
end
|
||||
end
|
5
spec/support/authentication.rb
Normal file
5
spec/support/authentication.rb
Normal file
@ -0,0 +1,5 @@
|
||||
module Authentication
|
||||
def sign_in(user, password)
|
||||
page.driver.post(sessions_url, email: user.email, password: password)
|
||||
end
|
||||
end
|
52
spec/support/controllers.rb
Normal file
52
spec/support/controllers.rb
Normal file
@ -0,0 +1,52 @@
|
||||
def expect_assigns(pairs)
|
||||
pairs.each_pair do |key, value|
|
||||
it "assigns @#{key}" do
|
||||
if value.is_a?(Class)
|
||||
expect(assigns(key)).to be_a(value)
|
||||
else
|
||||
object = value.is_a?(Symbol) ? send(value) : value
|
||||
if object.is_a?(ActiveRecord::Relation) || object.is_a?(Array)
|
||||
expect(assigns(key)).to match_array(object)
|
||||
else
|
||||
expect(assigns(key)).to eq(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def expect_content_type(content_type)
|
||||
it "responds with content type '#{content_type}'" do
|
||||
expect([response.content_type, response.headers['Content-Type']]).to include(content_type)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_flash_message(type, message)
|
||||
it 'displays a flash message' do
|
||||
expect(flash[type]).to eq(message.is_a?(String) ? message : I18n.t(message))
|
||||
end
|
||||
end
|
||||
|
||||
def expect_redirect(path = nil)
|
||||
if path
|
||||
it "redirects to #{path}" do
|
||||
expect(controller).to redirect_to(path)
|
||||
end
|
||||
else
|
||||
it 'performs a redirect' do
|
||||
expect(response).to be_redirect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def expect_status(status)
|
||||
it "responds with status #{status}" do
|
||||
expect(response.status).to eq(status)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_template(template)
|
||||
it "renders the '#{template}' template" do
|
||||
expect(controller).to render_template(template)
|
||||
end
|
||||
end
|
12
spec/support/database_cleaner.rb
Normal file
12
spec/support/database_cleaner.rb
Normal file
@ -0,0 +1,12 @@
|
||||
require 'database_cleaner'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
DatabaseCleaner.clean_with(:truncation)
|
||||
end
|
||||
|
||||
config.around(:each) do |example|
|
||||
DatabaseCleaner.cleaning { example.run }
|
||||
end
|
||||
end
|
12
spec/support/docker.rb
Normal file
12
spec/support/docker.rb
Normal file
@ -0,0 +1,12 @@
|
||||
IMAGE = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex)
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before(:each) do |example|
|
||||
unless example.metadata[:docker]
|
||||
allow(DockerClient).to receive(:check_availability!).and_return(true)
|
||||
allow(DockerClient).to receive(:image_tags).and_return([IMAGE])
|
||||
allow_any_instance_of(DockerClient).to receive(:find_image_by_tag).and_return(IMAGE)
|
||||
allow_any_instance_of(ExecutionEnvironment).to receive(:working_docker_image?)
|
||||
end
|
||||
end
|
||||
end
|
17
spec/support/features.rb
Normal file
17
spec/support/features.rb
Normal file
@ -0,0 +1,17 @@
|
||||
def expect_forbidden_path(path_name)
|
||||
it "forbids to access the #{path_name.to_s.split('_').join(' ')}" do
|
||||
visit(send(path_name))
|
||||
expect_path('/')
|
||||
end
|
||||
end
|
||||
|
||||
def expect_path(path)
|
||||
expect(URI.parse(current_url).path).to eq(path)
|
||||
end
|
||||
|
||||
def expect_permitted_path(path_name)
|
||||
it "permits to access the #{path_name.to_s.split('_').join(' ')}" do
|
||||
visit(send(path_name))
|
||||
expect_path(send(path_name))
|
||||
end
|
||||
end
|
11
spec/support/wait_for_ajax.rb
Normal file
11
spec/support/wait_for_ajax.rb
Normal file
@ -0,0 +1,11 @@
|
||||
module WaitForAjax
|
||||
def wait_for_ajax
|
||||
Timeout.timeout(Capybara.default_wait_time) do
|
||||
loop until ajax_requests_finished?
|
||||
end
|
||||
end
|
||||
|
||||
def ajax_requests_finished?
|
||||
page.evaluate_script('jQuery.active').zero?
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user