Skip to content

Commit

Permalink
spec: mocha => rspec-mocks for helpers
Browse files Browse the repository at this point in the history
Change-Id: I1666114ca3fca4346d1c4faddf59d59f4355e391
Reviewed-on: https://gerrit.instructure.com/120502
Tested-by: Jenkins
Reviewed-by: Rob Orton <[email protected]>
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Jul 26, 2017
1 parent cebbb8e commit 8fc3413
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 125 deletions.
76 changes: 38 additions & 38 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@

describe '#context_sensitive_datetime_title' do
it "produces a string showing the local time and the course time" do
context = stub(time_zone: ActiveSupport::TimeZone["America/Denver"])
context = double(time_zone: ActiveSupport::TimeZone["America/Denver"])
expect(context_sensitive_datetime_title(Time.now, context)).to eq "data-tooltip data-html-tooltip-title=\"Local: Mar 13 at 1:12am<br>Course: Mar 13 at 3:12am\""
end

it "only prints the text if just_text option passed" do
context = stub(time_zone: ActiveSupport::TimeZone["America/Denver"])
context = double(time_zone: ActiveSupport::TimeZone["America/Denver"])
expect(context_sensitive_datetime_title(Time.now, context, just_text: true)).to eq "Local: Mar 13 at 1:12am<br>Course: Mar 13 at 3:12am"
end

it "uses the simple title if theres no timezone difference" do
context = stub(time_zone: ActiveSupport::TimeZone["America/Anchorage"])
context = double(time_zone: ActiveSupport::TimeZone["America/Anchorage"])
expect(context_sensitive_datetime_title(Time.now, context, just_text: true)).to eq "Mar 13 at 1:12am"
expect(context_sensitive_datetime_title(Time.now, context)).to eq "data-tooltip data-html-tooltip-title=\"Mar 13 at 1:12am\""
end
Expand All @@ -124,14 +124,14 @@

it 'crosses date boundaries appropriately' do
Timecop.freeze(Time.utc(2013,3,13,7,12)) do
context = stub(time_zone: ActiveSupport::TimeZone["America/Denver"])
context = double(time_zone: ActiveSupport::TimeZone["America/Denver"])
expect(context_sensitive_datetime_title(Time.now, context)).to eq "data-tooltip data-html-tooltip-title=\"Local: Mar 12 at 11:12pm<br>Course: Mar 13 at 1:12am\""
end
end
end

describe '#friendly_datetime' do
let(:context) { stub(time_zone: ActiveSupport::TimeZone["America/Denver"]) }
let(:context) { double(time_zone: ActiveSupport::TimeZone["America/Denver"]) }

it 'spits out a friendly time tag' do
tag = friendly_datetime(Time.now)
Expand Down Expand Up @@ -229,21 +229,21 @@ def set_up_subaccounts

context "with no custom css" do
it "should be empty" do
helper.stubs(:active_brand_config).returns(nil)
allow(helper).to receive(:active_brand_config).and_return(nil)
expect(helper.include_account_css).to be_nil
end
end

context "with custom css" do
it "should include account css" do
helper.stubs(:active_brand_config).returns BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css')
allow(helper).to receive(:active_brand_config).and_return BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css')
output = helper.include_account_css
expect(output).to have_tag 'link'
expect(output).to match %r{https://example.com/path/to/overrides.css}
end

it "should include site_admin css even if there is no active brand" do
helper.stubs(:active_brand_config).returns nil
allow(helper).to receive(:active_brand_config).and_return nil
Account.site_admin.create_brand_config!({
css_overrides: 'https://example.com/site_admin/account.css',
js_overrides: 'https://example.com/site_admin/account.js'
Expand All @@ -255,7 +255,7 @@ def set_up_subaccounts


it "should not include anything if param is set to 0" do
helper.stubs(:active_brand_config).returns BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css')
allow(helper).to receive(:active_brand_config).and_return BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css')
params[:global_includes] = '0'

output = helper.include_account_css
Expand Down Expand Up @@ -338,20 +338,20 @@ def set_up_subaccounts

context "with no custom js" do
it "should be empty" do
helper.stubs(:active_brand_config).returns(nil)
allow(helper).to receive(:active_brand_config).and_return(nil)
expect(helper.include_account_js).to be_nil
end
end

context "with custom js" do
it "should include account javascript" do
helper.stubs(:active_brand_config).returns BrandConfig.create!(js_overrides: 'https://example.com/path/to/overrides.js')
allow(helper).to receive(:active_brand_config).and_return BrandConfig.create!(js_overrides: 'https://example.com/path/to/overrides.js')
output = helper.include_account_js
expect(output).to have_tag 'script', text: %r{https:\\/\\/example.com\\/path\\/to\\/overrides.js}
end

it "should include site_admin javascript even if there is no active brand" do
helper.stubs(:active_brand_config).returns nil
allow(helper).to receive(:active_brand_config).and_return nil
Account.site_admin.create_brand_config!({
css_overrides: 'https://example.com/site_admin/account.css',
js_overrides: 'https://example.com/site_admin/account.js'
Expand Down Expand Up @@ -529,7 +529,7 @@ def set_up_subaccounts
tool = @course.context_external_tools.new(:name => "bob", :consumer_key => "test", :shared_secret => "secret", :url => "http://example.com")
tool.editor_button = {:url => "http://example.com", :icon_url => "http://example.com", :canvas_icon_class => 'icon-commons'}
tool.save!
controller.stubs(:group_external_tool_path).returns('http://dummy')
allow(controller).to receive(:group_external_tool_path).and_return('http://dummy')
@context = @course

expect(editor_buttons).to eq([{:name=>"bob", :id=>tool.id, :url=>"http://example.com", :icon_url=>"http://example.com", :canvas_icon_class => 'icon-commons', :width=>800, :height=>400}])
Expand All @@ -555,7 +555,7 @@ def set_up_subaccounts
describe "UI path checking" do
describe "#active_path?" do
context "when the request path is the course show page" do
let(:request){ stub('request', :fullpath => '/courses/2')}
let(:request){ double('request', :fullpath => '/courses/2')}

it "returns true for paths that match" do
expect(active_path?('/courses')).to be_truthy
Expand All @@ -571,11 +571,11 @@ def set_up_subaccounts
end

context "when the request path is the account external tools path" do
let(:request){ stub('request', :fullpath => '/accounts/2/external_tools/27')}
let(:request){ double('request', :fullpath => '/accounts/2/external_tools/27')}

before :each do
@context = Account.default
controller.stubs(:controller_name).returns('external_tools')
allow(controller).to receive(:controller_name).and_return('external_tools')
end

it "it doesn't return true for '/accounts'" do
Expand All @@ -584,11 +584,11 @@ def set_up_subaccounts
end

context "when the request path is the course external tools path" do
let(:request){ stub('request', :fullpath => '/courses/2/external_tools/27')}
let(:request){ double('request', :fullpath => '/courses/2/external_tools/27')}

before :each do
@context = Account.default.courses.create!
controller.stubs(:controller_name).returns('external_tools')
allow(controller).to receive(:controller_name).and_return('external_tools')
end

it "returns true for '/courses'" do
Expand Down Expand Up @@ -619,14 +619,14 @@ def set_up_subaccounts
end

it "returns 'K12 Theme' by default for a k12 school" do
helper.stubs(:k12?).returns(true)
BrandConfig.stubs(:k12_config)
allow(helper).to receive(:k12?).and_return(true)
allow(BrandConfig).to receive(:k12_config)
expect(helper.send(:active_brand_config)).to eq BrandConfig.k12_config
end

it "returns 'K12 Theme' if a k12 school has chosen 'canvas default' in Theme Editor" do
helper.stubs(:k12?).returns(true)
BrandConfig.stubs(:k12_config)
allow(helper).to receive(:k12?).and_return(true)
allow(BrandConfig).to receive(:k12_config)

# this is what happens if you pick "Canvas Default" from the theme picker
session[:brand_config_md5] = false
Expand All @@ -639,27 +639,27 @@ def set_up_subaccounts

describe "include_head_js" do
before do
helper.stubs(:js_bundles).returns([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]])
allow(helper).to receive(:js_bundles).and_return([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]])
end

it "creates the correct javascript tags" do
helper.stubs(:js_env).returns({
allow(helper).to receive(:js_env).and_return({
BIGEASY_LOCALE: 'nb_NO',
MOMENT_LOCALE: 'nb',
TIMEZONE: 'America/La_Paz',
CONTEXT_TIMEZONE: 'America/Denver'
})
base_url = helper.use_optimized_js? ? 'dist/webpack-production' : 'dist/webpack-dev'
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/vendor.js').returns('vendor_url')
Canvas::Cdn::RevManifest.stubs(:revved_url_for).with('timezone/America/La_Paz.js').returns('La_Paz_url')
Canvas::Cdn::RevManifest.stubs(:revved_url_for).with('timezone/America/Denver.js').returns('Denver_url')
Canvas::Cdn::RevManifest.stubs(:revved_url_for).with('timezone/nb_NO.js').returns('nb_NO_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/moment/locale/nb.js').returns('nb_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/appBootstrap.js').returns('app_bootstrap_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/common.js').returns('common_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_bundle.js').returns('some_bundle_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').returns('plugin_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/another_bundle.js').returns('another_bundle_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/vendor.js').and_return('vendor_url')
allow(Canvas::Cdn::RevManifest).to receive(:revved_url_for).with('timezone/America/La_Paz.js').and_return('La_Paz_url')
allow(Canvas::Cdn::RevManifest).to receive(:revved_url_for).with('timezone/America/Denver.js').and_return('Denver_url')
allow(Canvas::Cdn::RevManifest).to receive(:revved_url_for).with('timezone/nb_NO.js').and_return('nb_NO_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/moment/locale/nb.js').and_return('nb_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/appBootstrap.js').and_return('app_bootstrap_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/common.js').and_return('common_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_bundle.js').and_return('some_bundle_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').and_return('plugin_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/another_bundle.js').and_return('another_bundle_url')

expect(helper.include_head_js).to eq %{
<script src="/vendor_url" defer="defer"></script>
Expand All @@ -678,13 +678,13 @@ def set_up_subaccounts

describe "include_js_bundles" do
before do
helper.stubs(:js_bundles).returns([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]])
allow(helper).to receive(:js_bundles).and_return([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]])
end
it "creates the correct javascript tags" do
base_url = helper.use_optimized_js? ? 'dist/webpack-production' : 'dist/webpack-dev'
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_bundle.js').returns('some_bundle_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').returns('plugin_url')
Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/another_bundle.js').returns('another_bundle_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_bundle.js').and_return('some_bundle_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').and_return('plugin_url')
allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/another_bundle.js').and_return('another_bundle_url')

expect(helper.include_js_bundles).to eq %{
<script src="/some_bundle_url" defer="defer"></script>
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/attachment_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

it "should return a valid crocodoc session url" do
@current_user = @student
@att.stubs(:crocodoc_available?).returns(true)
allow(@att).to receive(:crocodoc_available?).and_return(true)
attrs = doc_preview_attributes(@att)
expect(attrs).to match /crocodoc_session/
expect(attrs).to match /#{@current_user.id}/
Expand All @@ -38,7 +38,7 @@

it "should return a valid canvadoc session url" do
@current_user = @student
@att.stubs(:canvadocable?).returns(true)
allow(@att).to receive(:canvadocable?).and_return(true)
attrs = doc_preview_attributes(@att)
expect(attrs).to match /canvadoc_session/
expect(attrs).to match /#{@current_user.id}/
Expand Down
8 changes: 4 additions & 4 deletions spec/helpers/avatar_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def service_enabled?(type)

describe ".avatar_image_attrs" do
it "accepts a user id" do
self.expects(:avatar_url_for_user).with(user).returns("test_url")
expect(self).to receive(:avatar_url_for_user).with(user).and_return("test_url")
expect(avatar_image_attrs(user.id)).to eq ["test_url", user.short_name]
end

it "accepts a user" do
self.expects(:avatar_url_for_user).with(user).returns("test_url")
expect(self).to receive(:avatar_url_for_user).with(user).and_return("test_url")
expect(avatar_image_attrs(user)).to eq ["test_url", user.short_name]
end

Expand All @@ -48,7 +48,7 @@ def service_enabled?(type)
end

it "falls back to blank avatar when user's avatar has been reported during this session" do
self.expects(:session).at_least_once.returns({"reported_#{user.id}" => true})
expect(self).to receive(:session).at_least(:once).and_return({"reported_#{user.id}" => true})
expect(avatar_image_attrs(user)).to eq ["/images/messages/avatar-50.png", '']
end

Expand All @@ -69,7 +69,7 @@ def service_enabled?(type)
end

it "links to the context user's page when given a context_code" do
self.expects(:context_prefix).with('course_1').returns('/courses/1')
expect(self).to receive(:context_prefix).with('course_1').and_return('/courses/1')
expect(avatar(user, context_code: "course_1")).to match("href=\"/courses/1/users/#{user.id}\"")
end

Expand Down
Loading

0 comments on commit 8fc3413

Please sign in to comment.