Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNOE-433] Fix flash helper for angular 1.6 #283

Merged
merged 1 commit into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def callback
path = session.delete(:redirect_path).presence || mnoe_home_path

if error_key = params.fetch(:oauth, {})[:error]

path = add_param_to_fragment(path.to_s, 'flash', [{msg: error_message(error_key), type: :error}.to_json])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ module MnoEnterprise
describe "GET #show" do
subject { get :show, id: invite.id, token: token}

let(:success_fragment) { "#?dhbRefId=#{invite.organization.id}&#{URI.encode_www_form([['flash', {msg: "You are now part of #{invite.organization.name}", type: :success}.to_json]])}" }
let(:expired_fragment) { "#?#{URI.encode_www_form([['flash', {msg: "It looks like this invite has expired. Please ask your company administrator to resend the invite.", type: :error}.to_json]])}" }
let(:invalid_fragment) { "#?#{URI.encode_www_form([['flash', {msg: "Unfortunately, this invite does not seem to be valid.", type: :error}.to_json]])}" }
let(:success_fragment) { "#!?dhbRefId=#{invite.organization.id}&#{URI.encode_www_form([['flash', {msg: "You are now part of #{invite.organization.name}", type: :success}.to_json]])}" }
let(:expired_fragment) { "#!?#{URI.encode_www_form([['flash', {msg: "It looks like this invite has expired. Please ask your company administrator to resend the invite.", type: :error}.to_json]])}" }
let(:invalid_fragment) { "#!?#{URI.encode_www_form([['flash', {msg: "Unfortunately, this invite does not seem to be valid.", type: :error}.to_json]])}" }

context 'when not signed in' do
it { expect(subject).not_to be_success }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module MnoEnterprise
describe "unauthorized" do
let(:authorized) { false }

let(:error_fragment) { "#?#{URI.encode_www_form([['flash', {msg: "Unfortunately you do not have permission to purchase products for this organization", type: :error}.to_json]])}" }
let(:error_fragment) { "#!?#{URI.encode_www_form([['flash', {msg: "Unfortunately you do not have permission to purchase products for this organization", type: :error}.to_json]])}" }

it 'redirect to the dashboard with an error message' do
expect(response).to redirect_to(mnoe_home_path + error_fragment)
Expand Down Expand Up @@ -89,7 +89,7 @@ module MnoEnterprise

context 'with one organization available' do
let(:organizations) { [organization] }
let(:error_fragment) { "#?#{URI.encode_www_form([['flash', {msg: "Unfortunately you do not have permission to purchase products for this organization", type: :error}.to_json]])}" }
let(:error_fragment) { "#!?#{URI.encode_www_form([['flash', {msg: "Unfortunately you do not have permission to purchase products for this organization", type: :error}.to_json]])}" }

it 'redirect to the dashboard with an error message' do
expect(response).to redirect_to(mnoe_home_path + error_fragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module MnoEnterprise
context 'when there is on oauth error' do
subject { get :callback, id: app_instance.uid, oauth: {error: :unauthorized} }

let(:fragment) { "#?#{URI.encode_www_form([['flash', {msg: 'We could not validate your credentials, please try again', type: :error}.to_json]])}" }
let(:fragment) { "#!?#{URI.encode_www_form([['flash', {msg: 'We could not validate your credentials, please try again', type: :error}.to_json]])}" }

it { subject; expect(response).to redirect_to(MnoEnterprise.router.dashboard_path + fragment) }
end
Expand Down
10 changes: 5 additions & 5 deletions core/app/controllers/mno_enterprise/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def after_sign_out_path_for(resource_or_scope)
private

# Append params to the fragment part of an existing url String
# add_param("/#/platform/accounts", 'foo', 'bar')
# => "/#/platform/accounts?foo=bar"
# add_param("/#/platform/dashboard/he/43?en=690", 'foo', 'bar')
# => "/#/platform/dashboard/he/43?en=690&foo=bar"
# add_param_to_fragment("/#!/platform/accounts", 'foo', 'bar')
# => "/#!/platform/accounts?foo=bar"
# add_param_to_fragment("/#!/platform/dashboard/he/43?en=690", 'foo', 'bar')
# => "/#!/platform/dashboard/he/43?en=690&foo=bar"
def add_param_to_fragment(url, param_name, param_value)
uri = URI(url)
fragment = URI(uri.fragment || "")
fragment = URI(uri.fragment || "!")
params = URI.decode_www_form(fragment.query || "") << [param_name, param_value]
fragment.query = URI.encode_www_form(params)
uri.fragment = fragment.to_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def add_param_to_fragment(url, param_name, param_value)
end

describe '#add_param_to_fragment' do
it { expect(controller.add_param_to_fragment('/#/platform/accounts', 'foo', 'bar')).to eq('/#/platform/accounts?foo=bar') }
it { expect(controller.add_param_to_fragment('/', 'foo', 'bar')).to eq('/#?foo=bar') }
it { expect(controller.add_param_to_fragment('/#/platform/dashboard/he/43?en=690', 'foo', 'bar')).to eq('/#/platform/dashboard/he/43?en=690&foo=bar') }
it { expect(controller.add_param_to_fragment('/#/platform/dashboard/he/43?en=690', 'foo', [{msg: 'yolo'}])).to eq('/#/platform/dashboard/he/43?en=690&foo=%7B%3Amsg%3D%3E%22yolo%22%7D') }
it { expect(controller.add_param_to_fragment('/#!/platform/accounts', 'foo', 'bar')).to eq('/#!/platform/accounts?foo=bar') }
it { expect(controller.add_param_to_fragment('/', 'foo', 'bar')).to eq('/#!?foo=bar') }
it { expect(controller.add_param_to_fragment('/#!/platform/dashboard/he/43?en=690', 'foo', 'bar')).to eq('/#!/platform/dashboard/he/43?en=690&foo=bar') }
it { expect(controller.add_param_to_fragment('/#!/platform/dashboard/he/43?en=690', 'foo', [{msg: 'yolo'}])).to eq('/#!/platform/dashboard/he/43?en=690&foo=%7B%3Amsg%3D%3E%22yolo%22%7D') }
end

describe '#after_sign_in_path_for' do
Expand Down