Skip to content

Commit

Permalink
Merge pull request #2275 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-10-02
  • Loading branch information
yachtcaptain23 authored Oct 2, 2019
2 parents 6eeee0b + 101479d commit 0a35a64
Show file tree
Hide file tree
Showing 19 changed files with 1,045 additions and 139 deletions.
24 changes: 17 additions & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ApplicationController < ActionController::Base

protect_from_forgery prepend: true, with: :exception

before_action :set_locale
before_action :set_paper_trail_whodunnit
before_action :no_cache

Expand All @@ -20,12 +19,23 @@ class ApplicationController < ActionController::Base
end

around_action :switch_locale

def switch_locale(&action)
locale = params[:locale] || I18n.default_locale
locale = nil
locale = params[:locale] if params[:locale].present?

if locale.nil? && extract_locale_from_accept_language_header == 'ja'
new_query = URI(request.original_url).query.present? ? "&locale=ja" : "?locale=ja"
redirect_to(request.original_url + new_query) and return
end

locale = I18n.default_locale if locale.nil?
I18n.with_locale(locale, &action)
end

def default_url_options
{ locale: I18n.locale }
end

def no_cache
return if controller_name == 'static' # We want to cache on the homepage
response.headers['Cache-Control'] = 'no-cache, no-store'
Expand All @@ -43,10 +53,6 @@ def current_ability
@current_ability ||= Ability.new(current_user, request.remote_ip)
end

def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end

def handle_unverified_request
respond_to do |format|
format.html {
Expand All @@ -61,4 +67,8 @@ def handle_unverified_request
def u2f
@u2f ||= U2F::U2F.new(request.base_url)
end

def extract_locale_from_accept_language_header
request.env['HTTP_ACCEPT_LANGUAGE']&.scan(/^[a-z]{2}/)&.first
end
end
944 changes: 944 additions & 0 deletions config/locales/ja.yml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/controllers/admin/organizations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Admin::OrganizationsControllerTest < ActionDispatch::IntegrationTest

it "redirects to organization when saved" do
organization = controller.instance_variable_get("@organization")
assert_redirected_to admin_organization_path(Organization.find_by(name: organization_name))
# assert_redirected_to admin_organization_path(Organization.find_by(name: organization_name))
assert_redirected_to controller: '/admin/organizations', action: :show, id: organization.id
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/admin/publisher_notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PublisherNotesControllerTest < ActionDispatch::IntegrationTest
end

it 'redirects to the publisher page' do
assert_redirected_to admin_publisher_path(publishers(:verified))
assert_redirected_to controller: '/admin/publishers', action: 'show', id: publishers(:verified).id
end
end

Expand Down Expand Up @@ -119,7 +119,7 @@ class PublisherNotesControllerTest < ActionDispatch::IntegrationTest
end

it 'redirects to the publisher page' do
assert_redirected_to admin_publisher_path(publishers(:verified))
assert_redirected_to controller: '/admin/publishers', action: 'show', id: publishers(:verified).id
end
end
end
Expand Down Expand Up @@ -170,7 +170,7 @@ class PublisherNotesControllerTest < ActionDispatch::IntegrationTest
end

it 'redirects to the publisher page' do
assert_redirected_to admin_publisher_path(publishers(:verified))
assert_redirected_to controller: '/admin/publishers', action: 'show', id: publishers(:verified).id
end
end
end
Expand Down Expand Up @@ -229,7 +229,7 @@ class PublisherNotesControllerTest < ActionDispatch::IntegrationTest
before { subject }

it 'redirects to the publisher page' do
assert_redirected_to admin_publisher_path(publishers(:just_notes).id)
assert_redirected_to controller: '/admin/publishers', action: 'show', id: publishers(:just_notes).id
end

it 'deletes the note' do
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/channel_transfer_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChannelTransferControllerTest < ActionDispatch::IntegrationTest
get token_reject_transfer_path(channel, channel.contest_token)
end

assert_redirected_to home_publishers_path
assert_redirected_to controller: '/publishers', action: 'home'
assert_equal I18n.t("shared.channel_transfer_rejected"), flash[:notice]
end

Expand All @@ -30,7 +30,7 @@ class ChannelTransferControllerTest < ActionDispatch::IntegrationTest
get token_reject_transfer_path(channel, "fake token")

assert response.status, 404
assert_redirected_to home_publishers_path
assert_redirected_to controller: '/publishers', action: 'home'
assert_equal I18n.t("shared.channel_not_found"), flash[:notice]
end
end
4 changes: 2 additions & 2 deletions test/controllers/channels_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ChannelsControllerTest < ActionDispatch::IntegrationTest
assert_difference("publisher.channels.count", -1) do
assert_difference("SiteChannelDetails.count", -1) do
get cancel_add_channel_path(channel)
assert_redirected_to '/publishers/home'
assert_redirected_to controller: "/publishers", action: "home"
end
end
end
Expand All @@ -82,7 +82,7 @@ class ChannelsControllerTest < ActionDispatch::IntegrationTest
assert_difference("publisher.channels.count", 0) do
assert_difference("SiteChannelDetails.count", 0) do
get cancel_add_channel_path(channel)
assert_redirected_to '/publishers/home'
assert_redirected_to controller: "/publishers", action: "home"
end
end
end
Expand Down
48 changes: 24 additions & 24 deletions test/controllers/publishers/omniauth_callbacks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def channel_data(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_youtube_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
end
channel = Channel.order(created_at: :asc).last

Expand Down Expand Up @@ -131,7 +131,7 @@ def channel_data(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_youtube_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down Expand Up @@ -160,7 +160,7 @@ def channel_data(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_youtube_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand All @@ -178,7 +178,7 @@ def channel_data(options = {})

post(publisher_register_youtube_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!

# Channel was transferred
Expand Down Expand Up @@ -220,7 +220,7 @@ def channel_data(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_youtube_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down Expand Up @@ -260,7 +260,7 @@ def auth_hash(options = {})

post(publisher_youtube_login_omniauth_authorize_url)
follow_redirect!
assert_redirected_to change_email_publishers_path
assert_redirected_to controller: "/publishers", action: "change_email"
end

test "a publisher who does not have a google plus email can not login using their login channel" do
Expand All @@ -275,15 +275,15 @@ def auth_hash(options = {})

post(publisher_youtube_login_omniauth_authorize_url)
follow_redirect!
assert_redirected_to log_in_publishers_path
assert_redirected_to controller: "registrations", action: "log_in"
end

test "a publisher who was registered by youtube channel signup can't add additional youtube channels" do
OmniAuth.config.mock_auth[:youtube_login] = auth_hash

post(publisher_youtube_login_omniauth_authorize_url)
follow_redirect!
assert_redirected_to change_email_publishers_path
assert_redirected_to controller: "/publishers", action: "change_email"

OmniAuth.config.mock_auth[:register_youtube_channel] = OmniAuth::AuthHash.new(
{
Expand Down Expand Up @@ -330,9 +330,9 @@ def auth_hash(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_youtube_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
assert_redirected_to change_email_publishers_path
assert_redirected_to controller: "/publishers", action: "change_email"
end
end
end
Expand Down Expand Up @@ -374,7 +374,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_twitch_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
end
channel = Channel.order(created_at: :asc).last

Expand All @@ -398,7 +398,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_twitch_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down Expand Up @@ -456,7 +456,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_twitter_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
end

channel = Channel.order(created_at: :asc).last
Expand Down Expand Up @@ -485,7 +485,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_twitter_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand All @@ -508,7 +508,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_twitter_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down Expand Up @@ -565,7 +565,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_vimeo_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
end

channel = Channel.order(created_at: :asc).last
Expand All @@ -592,7 +592,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_vimeo_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand All @@ -619,7 +619,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_vimeo_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down Expand Up @@ -663,7 +663,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_reddit_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
end

channel = Channel.order(created_at: :asc).last
Expand All @@ -690,7 +690,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_reddit_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand All @@ -716,7 +716,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_reddit_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down Expand Up @@ -759,7 +759,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_github_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
end

channel = Channel.order(created_at: :asc).last
Expand All @@ -786,7 +786,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 1) do
post(publisher_register_github_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand All @@ -812,7 +812,7 @@ def auth_hash(options = {})
assert_difference("Channel.count", 0) do
post(publisher_register_github_channel_omniauth_authorize_url)
follow_redirect!
assert_redirected_to home_publishers_path
assert_redirected_to controller: "/publishers", action: "home"
follow_redirect!
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
end

it 'redirects back to the sign up page' do
assert_redirected_to sign_up_publishers_path
assert_redirected_to controller: '/publishers/registrations', action: 'sign_up'
end
end

Expand Down
Loading

0 comments on commit 0a35a64

Please sign in to comment.