Skip to content

Commit

Permalink
Skip tests that require plugin unless plugin installed
Browse files Browse the repository at this point in the history
fixes CNVS-36355

Test plan:

- docker-compose build --pull
- docker-compose run --rm web bundle exec rspec \
  spec/{apis,controllers,helpers,initializers,integration,lib,message,\
  middleware,migrations,models,observers,presenters,serializers,views}\
  /**/*_spec.rb

Change-Id: I4220a314dbc2e343dae26e6e522806f4f2666f85
Reviewed-on: https://gerrit.instructure.com/120671
Reviewed-by: Cody Cutrer <[email protected]>
Tested-by: Jenkins
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
Product-Review: Jon Jensen <[email protected]>
QA-Review: Jon Jensen <[email protected]>
  • Loading branch information
Omar Khan committed Jul 28, 2017
1 parent f7b1dec commit 0536054
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 18 deletions.
9 changes: 6 additions & 3 deletions gems/attachment_fu/lib/attachment_fu/backends/s3_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ class ConfigFileNotFoundError < StandardError; end
def self.included(base) #:nodoc:
require 'aws-sdk-s3'

s3_config_path = base.attachment_options[:s3_config_path] || (Rails.root + 'config/amazon_s3.yml')
s3_config = YAML.load(ERB.new(File.read(s3_config_path)).result)[Rails.env].symbolize_keys

s3_config = load_s3_config(base.attachment_options[:s3_config_path])
bucket_name = s3_config.delete(:bucket_name)

s3 = Aws::S3::Resource.new(Canvas::AWS.validate_v2_config(s3_config, 'amazon_s3.yml'))
Expand All @@ -153,6 +151,11 @@ def self.included(base) #:nodoc:
base.before_update :rename_file
end

def self.load_s3_config(path = nil)
s3_config_path = path || (Rails.root + 'config/amazon_s3.yml')
YAML.load(ERB.new(File.read(s3_config_path)).result)[Rails.env].symbolize_keys
end

# Overwrites the base filename writer in order to store the old filename
def filename=(value)
@old_filename = filename unless filename.nil? || @old_filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@

context "modules" do
it "should convert modules and module items" do
skip 'Requires QtiMigrationTool' unless Qti.qti_enabled?

expect(@course.context_modules.count).to eq 8
expect(@course.context_module_tags.where(:content_type => "Assignment", :title => "Assignment Name")).to be_exists
expect(@course.context_module_tags.where(:content_type => "WikiPage", :title => "My Sample Page")).to be_exists
Expand Down
2 changes: 2 additions & 0 deletions spec/apis/v1/master_courses/master_templates_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ def run_master_migration
end

it "returns change information from the minion side" do
skip 'Requires QtiMigrationTool' unless Qti.qti_enabled?

minion = @minions.first
minion_migration = minion.content_migrations.last
minion_page = minion.wiki.wiki_pages.where(migration_id: @template.migration_id_for(@page)).first
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/config_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

describe ConfigFile do
describe ".cache_object" do
before { ConfigFile.unstub }

it "caches objects" do
expect(File).to receive(:exist?).and_return(true)
expect(File).to receive(:read).and_return('test: {}')
Expand Down
2 changes: 2 additions & 0 deletions spec/models/content_migration/course_copy_dates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def copy_assignment(options = {})
end

it "should not break link resolution in quiz_data" do
skip 'Requires QtiMigrationTool' unless Qti.qti_enabled?

topic = @copy_from.discussion_topics.create!(:title => "some topic", :message => "<p>some text</p>")

html = "<a href='/courses/#{@copy_from.id}/discussion_topics/#{topic.id}'>link</a>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def self.send_imported_content(course, imported_content)
end

it "should translate ids for copied course content" do
skip 'Requires QtiMigrationTool' unless Qti.qti_enabled?

assmt = @copy_from.assignments.create!
topic = @copy_from.discussion_topics.create!(:message => "hi", :title => "discussion title")
ann = @copy_from.announcements.create!(:message => "goodbye")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
end

it "should not re-unpublish module items on re-copy" do
skip 'Requires QtiMigrationTool' unless Qti.qti_enabled?

mod = @copy_from.context_modules.create!(:name => "some module")
tags = []

Expand Down
2 changes: 2 additions & 0 deletions spec/models/content_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def test_zip_import(context)
end

it "should correclty handle media comment resolution in quizzes" do
skip 'Requires QtiMigrationTool' unless Qti.qti_enabled?

course_with_teacher
cm = ContentMigration.new(:context => @course, :user => @user)
cm.migration_type = 'canvas_cartridge_importer'
Expand Down
4 changes: 4 additions & 0 deletions spec/models/user_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
end

it "should not enroll the observer in institutions where they lack a login" do
unless has_sharding?
skip 'Sharding specs fail without additional support from a multi-tenancy plugin'
end

a1 = account_model
c1 = course_factory(account: a1, active_all: true)
e1 = student_in_course(course: c1, user: student, active_all: true)
Expand Down
20 changes: 15 additions & 5 deletions spec/sharding_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@
require_relative 'spec_helper'
require_relative 'support/onceler/sharding'

def has_sharding?
User.instance_method(:associated_shards).owner != User
end

def specs_require_sharding
include Switchman::RSpecHelper
include Onceler::Sharding
if has_sharding?
include Switchman::RSpecHelper
include Onceler::Sharding

before :all do
Shard.with_each_shard do
Role.ensure_built_in_roles!
before :all do
Shard.with_each_shard do
Role.ensure_built_in_roles!
end
end
else
before(:once) do
skip 'Sharding specs fail without additional support from a multi-tenancy plugin'
end
end
end
24 changes: 14 additions & 10 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def self.included(other)
end

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
require_relative 'sharding_spec_helper'

# nuke the db (say, if `rake db:migrate RAILS_ENV=test` created records),
# and then ensure people aren't creating records outside the rspec
Expand Down Expand Up @@ -398,6 +399,10 @@ def using_transactions_properly?
Timecop.safe_mode = true
end

config.before do
allow(AttachmentFu::Backends::S3Backend).to receive(:load_s3_config) { StubS3::AWS_CONFIG.dup }
end

# this runs on post-merge builds to capture dependencies of each spec;
# we then use that data to run just the bare minimum subset of selenium
# specs on the patchset builds
Expand Down Expand Up @@ -661,21 +666,20 @@ def as(ancestor)
end

module StubS3
AWS_CONFIG = {
access_key_id: 'stub_id',
secret_access_key: 'stub_key',
region: 'us-east-1',
stub_responses: true,
bucket_name: 'no-bucket'
}.freeze

def self.stubbed?
false
end

def load(file, *args)
if StubS3.stubbed? && file == 'amazon_s3'
return {
access_key_id: 'stub_id',
secret_access_key: 'stub_key',
region: 'us-east-1',
stub_responses: true,
bucket_name: 'no-bucket'
}
end

return AWS_CONFIG.dup if StubS3.stubbed? && file == 'amazon_s3'
super
end
end
Expand Down

0 comments on commit 0536054

Please sign in to comment.