Skip to content

Commit

Permalink
addressed test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
briri committed Dec 2, 2020
1 parent d999fc5 commit b7fac3d
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 102 deletions.
3 changes: 2 additions & 1 deletion app/controllers/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def admin_update
@org.logo = attrs[:logo] if attrs[:logo]
tab = (attrs[:feedback_enabled].present? ? "feedback" : "profile")
@org.links = ActiveSupport::JSON.decode(params[:org_links]) if params[:org_links].present?

attrs.delete(:org_links)

# Only allow super admins to change the org types and shib info
if current_user.can_super_admin?
identifiers = []
Expand Down
2 changes: 1 addition & 1 deletion app/views/branded/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
active_page?(user_orcid_omniauth_callback_path) %>
<!-- Modal windows for sign in/out -->
<% unless user_signed_in? %>
<% if Rails.configuration.x.shibboleth_use_filtered_discovery_service %>
<% if Rails.configuration.x.shibboleth.use_filtered_discovery_service %>
<div id="shib-ds-form" class="modal fade" tabindex="-1" role="dialog">
<%= render partial: 'shared/shib_ds_form' %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/branded/layouts/mobile/_fixed_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
<i class="fas fa-sort-desc" aria-hidden="true">&nbsp;</i>
</a>
<ul class="dropdown-menu" aria-labelledby="signin-menu-button">
<% if Rails.configuration.x.shibboleth_enabled %>
<% if Rails.configuration.x.shibboleth.enabled %>
<!-- Shibboleth DS enabled -->
<li>
<% if request.fullpath != "/users/sign_up?nosplash=true" &&
session[:shibboleth_data].nil? %>
<% if Rails.configuration.x.shibboleth_use_filtered_discovery_service %>
<% if Rails.configuration.x.shibboleth.use_filtered_discovery_service %>
<%= link_to _('Sign in through an affiliated institution'), '#',
'data-toggle': 'modal',
'data-target': '#shib-ds-form' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/branded/shared/_get_started.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br>
<div class="form-group">
<% step_counter = 1 %>
<% if Rails.configuration.x.shibboleth_enabled %>
<% if Rails.configuration.x.shibboleth.enabled %>
<!-- Shibboleth DS enabled -->
<% if request.fullpath != "/users/sign_up?nosplash=true" && session[:shibboleth_data].nil? then%>
<h3><%= _('Option %{number}: If your institution is affiliated with DMPTool.') % { number: step_counter } %></h3>
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/orgs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

it "succeeds" do
@args.delete(:feedback_enabled)
put :admin_update, params: { id: @org.id, org: @args }
put :admin_update, params: { id: @org.id, org: @args, org_links: @args[:org_links] }
expect(response).to redirect_to("#{admin_edit_org_path(@org)}#profile")
expect(flash[:notice].present?).to eql(true)
@org.reload
Expand Down
1 change: 1 addition & 0 deletions spec/features/locales_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

before(:each) do
# Clear out the default defined in the locales support file
Org.destroy_all
Language.destroy_all
end

Expand Down
6 changes: 3 additions & 3 deletions spec/features/super_admins/orgs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# -------------------------------------------------------------

nbr_links = all('.link').length
addLink
add_link
expect(all('.link').length).to eql(nbr_links + 1)
end

Expand All @@ -72,9 +72,9 @@
# end DMPTool customization
# -------------------------------------------------------------

addLink
add_link
nbr_links = all('.link').length
removeLink
remove_link
expect(all('.link').length).to eql(nbr_links - 1)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mixins/controllers/dmptool/orgs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
it "redirects to the shibboleth IdP" do
id = create(:identifier, identifiable: @org, identifier_scheme: @shib)
@org = @org.reload
post shibboleth_ds_path, { id: @org.id }
post shibboleth_ds_path(id: @org.id)

location = response.headers["Location"]
expect(location.include?(Rails.application.config.shibboleth_login)).to eql(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
before(:each) do
@hash = {
info: {
name: Faker::Movies::StarWars.character,
name: Faker::Music::PearlJam.musician,
email: Faker::Internet.email,
identity_provider: @entity_id.value
}
Expand Down Expand Up @@ -243,27 +243,27 @@
expect(@controller.send(:extract_omniauth_names, hash: nil)).to eql({})
end
it "handles :givenname" do
hash = { givenname: Faker::Movies::StarWars.character.split.first }
hash = { givenname: Faker::Music::PearlJam.musician.split.first }
result = @controller.send(:extract_omniauth_names, hash: hash)
expect(result[:firstname]).to eql(hash[:givenname])
end
it "handles :firstname" do
hash = { firstname: Faker::Movies::StarWars.character.split.first }
hash = { firstname: Faker::Music::PearlJam.musician.split.first }
result = @controller.send(:extract_omniauth_names, hash: hash)
expect(result[:firstname]).to eql(hash[:firstname])
end
it "handles :lastname" do
hash = { lastname: Faker::Movies::StarWars.character.split.first }
hash = { lastname: Faker::Music::PearlJam.musician.split.first }
result = @controller.send(:extract_omniauth_names, hash: hash)
expect(result[:surname]).to eql(hash[:lastname])
end
it "handles :surname" do
hash = { surname: Faker::Movies::StarWars.character.split.first }
hash = { surname: Faker::Music::PearlJam.musician.split.first }
result = @controller.send(:extract_omniauth_names, hash: hash)
expect(result[:surname]).to eql(hash[:surname])
end
it "correctly splits :name into first and last" do
hash = { name: Faker::Movies::StarWars.character }
hash = { name: Faker::Music::PearlJam.musician }
result = @controller.send(:extract_omniauth_names, hash: hash)
names = hash[:name].split
expect(result[:firstname]).to eql(names.length > 1 ? names.first : nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/mixins/models/dmptool/org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
expect(@unmanaged.shibbolized?).to eql(false)
end
it "returns true" do
org = Org.participating.first
org = Org.participating.last
expect(org.shibbolized?).to eql(true)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/mixins/presenters/dmptool/org_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

describe "#initialize" do
it "initializes if a shibboleth scheme is available" do
expect(@presenter.is_a?(Presenters::Dmptool::OrgPresenter)).to eql(true)
expect(@presenter.is_a?(Dmptool::OrgPresenter)).to eql(true)
end
it "initializes if a shibboleth scheme is NOT available" do
@scheme.destroy
presenter = described_class.new
expect(presenter.is_a?(Presenters::Dmptool::OrgPresenter)).to eql(true)
expect(presenter.is_a?(Dmptool::OrgPresenter)).to eql(true)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
line_4: org[:address_line4],
country: org[:address_country]
}
# rubocop:enable Naming/VariableNumber
render
expect(rendered.include?("<strong>#{org[:name]}")).to eql(true)
expect(rendered.include?("#{org[:address_line1]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_line2]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_line3]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_line4]}<br>")).to eql(true)
expect(rendered.include?("<strong>#{CGI::escapeHTML(org[:name])}")).to eql(true)
expect(rendered.include?("#{org[:address_line_1]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_line_2]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_line_3]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_line_4]}<br>")).to eql(true)
expect(rendered.include?("#{org[:address_country]}<br>")).to eql(true)
expect(rendered.include?("<iframe")).to eql(true)
# rubocop:enable Naming/VariableNumber
end

end
31 changes: 16 additions & 15 deletions spec/views/branded/layouts/_analytics.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,54 @@
controller.prepend_view_path "app/views/branded"
org = create(:org, name: ApplicationService.application_name,
abbreviation: ApplicationService.application_name)
create(:tracker, org: org)
create(:tracker, org: org, code: "UA-123456789-0")
org.reload
gkey = org.trackers.last.value
@gkey = org.tracker.code
@expected_usersnap = "//api.usersnap.com/load/#{SecureRandom.uuid}.js"
@expected_google = "https://www.googletagmanager.com/gtag/js?id=#{gkey}"
Rails.env.stubs(:stage?).returns(true)
Rails.env.stubs(:production?).returns(false)
Rails.configuration.x.google_analytics.tracker_root = @gkey
Rails.application.credentials.stubs(:usersnap).returns({ key: @expected_usersnap })
Rails.configuration.x.google_analytics.tracker_root = ApplicationService.application_name
end

context "renders nothing" do
it "when Rails.configuration.branding[:keys] is empty" do
Rails.configuration.branding[:keys] = []
it "when Rails.configuration.x.google_analytics.tracker_root is empty" do
Rails.configuration.x.google_analytics.tracker_root = nil
render
expect(rendered.include?(@expected_usersnap)).to eql(false)
expect(rendered.include?(@expected_google)).to eql(false)
expect(rendered.include?(@expected_usersnap)).to eql(true)
expect(rendered.include?(@gkey)).to eql(false)
end
it "when :usersnap_key and :google_analytics_key are not present" do
Rails.configuration.branding[:keys] = []
Rails.configuration.x.google_analytics.tracker_root = nil
Rails.application.credentials.stubs(:usersnap).returns({ key: nil })
render
expect(rendered.include?(@expected_usersnap)).to eql(false)
expect(rendered.include?(@expected_google)).to eql(false)
expect(rendered.include?(@gkey)).to eql(false)
end
it "when Rails.env.stage? and Rails.env.production? are false" do
Rails.configuration.branding[:keys] = @keys
Rails.env.stubs(:stage?).returns(false)
Rails.env.stubs(:production?).returns(false)
render
expect(rendered.include?(@expected_usersnap)).to eql(false)
expect(rendered.include?(@expected_google)).to eql(false)
expect(rendered.include?(@gkey)).to eql(false)
end
end

it "Rails.env.stage?" do
Rails.configuration.branding[:keys] = @keys
Rails.env.stubs(:stage?).returns(true)
Rails.env.stubs(:production?).returns(false)
render
expect(rendered.include?(@expected_usersnap)).to eql(true)
expect(rendered.include?(@expected_google)).to eql(true)
expect(rendered.include?(@gkey)).to eql(true)
end

it "Rails.env.production?" do
Rails.configuration.branding[:keys] = @keys
Rails.env.stubs(:stage?).returns(false)
Rails.env.stubs(:production?).returns(true)
render
expect(rendered.include?(@expected_usersnap)).to eql(false)
expect(rendered.include?(@expected_google)).to eql(true)
expect(rendered.include?(@gkey)).to eql(true)
end

end
3 changes: 0 additions & 3 deletions spec/views/branded/layouts/_logo.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
it "renders correctly when user is logged in" do
sign_in create(:user, org: @org)
render

p rendered

expect(rendered.include?("org-logo")).to eql(true)
expect(rendered.include?(@org.name)).to eql(true)
expect(rendered.include?("app-logo")).to eql(false)
Expand Down
8 changes: 4 additions & 4 deletions spec/views/branded/layouts/application.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
describe "layouts/application.html.erb" do

before(:each) do
@app_name = Faker::Company.name
@app_name = ApplicationService.application_name
Rails.configuration.x.application.name = @app_name
controller.prepend_view_path "app/views/branded"
end

it "displays correctly when user is not logged in and Shib is NOT enabled" do
Rails.configuration.shibboleth.use_filtered_discovery_service = false
Rails.configuration.x.shibboleth.use_filtered_discovery_service = false
render
expect(response).to render_template(partial: "layouts/_analytics")
expect(rendered.include?("<title>#{@app_name}")).to eql(true)
Expand All @@ -30,7 +30,7 @@
end

it "displays correctly when user is not logged in and Shib is enabled" do
Rails.configuration.shibboleth.use_filtered_discovery_service = true
Rails.configuration.x.shibboleth.use_filtered_discovery_service = true
render
expect(response).to render_template(partial: "layouts/_analytics")
expect(rendered.include?("<title>#{@app_name}")).to eql(true)
Expand All @@ -49,7 +49,7 @@
end

it "displays correctly when user is logged in" do
Rails.configuration.shibboleth.use_filtered_discovery_service = true
Rails.configuration.x.shibboleth.use_filtered_discovery_service = true
sign_in create(:user)
render
expect(response).to render_template(partial: "layouts/_analytics")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

context "user not logged in when Shibboleth is enabled" do
it "renders our version of the page" do
Rails.application.config.shibboleth_enabled = true
Rails.configuration.x.shibboleth.enabled = true
render
expect(rendered.include?("DMPTool_logo_blue_shades_v1b3b.svg")).to eql(true)
expect(rendered.include?("DMPTool_logo_blue_shades_v1b3b")).to eql(true)
expect(rendered.include?("Sign in")).to eql(true)
expect(rendered.include?("Sign in through an affiliated institution")).to eql(true)
expect(rendered.include?("Sign in with your email address")).to eql(true)
Expand All @@ -27,9 +27,9 @@

context "user not logged in when Shibboleth is NOT enabled" do
it "renders our version of the page" do
Rails.application.config.shibboleth_enabled = false
Rails.configuration.x.shibboleth.enabled = false
render
expect(rendered.include?("DMPTool_logo_blue_shades_v1b3b.svg")).to eql(true)
expect(rendered.include?("DMPTool_logo_blue_shades_v1b3b")).to eql(true)
expect(rendered.include?("Sign in")).to eql(true)
expect(rendered.include?("Sign in through an affiliated institution")).to eql(false)
expect(rendered.include?("Sign in with your email address")).to eql(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/branded/paginable/orgs/_public.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

controller.prepend_view_path "app/views/branded"
assign :paginable_path_params, { sort_field: "orgs.name", sort_direction: :asc }
assign :paginable_params, { controller: "paginable/orgs", action: "public" }
assign :args, { controller: "paginable/orgs", action: "public" }
# Paginable is expecting `scope` to be a local not an instance variable
render partial: "paginable/orgs/public", locals: { scope: Org.participating }
expect(rendered.include?("Institutional Signin Enabled")).to eql(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
2.times { create(:template, :published, org: org) }
controller.prepend_view_path "app/views/branded"
assign :paginable_path_params, { sort_field: "templates.title", sort_direction: :asc }
assign :paginable_params, { controller: "paginable/orgs", action: "public" }
assign :args, { controller: "paginable/orgs", action: "public" }
# Paginable is expecting `scope` to be a local not an instance variable
render partial: "paginable/templates/publicly_visible", locals: { scope: Template.all }
expect(rendered.include?("Template")).to eql(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/branded/shared/org_branding.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@org.logo = nil
assign :user, build(:user, org: @org)
render
expect(rendered.include?("<h1>#{@org.name}</h1>")).to eql(true)
expect(rendered.include?("<h1>#{CGI::escapeHTML(@org.name)}</h1>")).to eql(true)
end

it "renders the Org logo if available" do
Expand Down
29 changes: 0 additions & 29 deletions spec/views/branded/user_mailer/admin_privileges.html.erb_spec.rb

This file was deleted.

19 changes: 0 additions & 19 deletions spec/views/branded/user_mailer/api_plan_creation.html.erb_spec.rb

This file was deleted.

0 comments on commit b7fac3d

Please sign in to comment.