-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class SettingsController < ApplicationController | ||
def provider | ||
provider = provider_scope.find(provider_params[:id]) | ||
cookies.signed[:current_provider_id] = provider.id if provider | ||
redirect_to request.referer || root_path | ||
end | ||
|
||
private | ||
|
||
def provider_params | ||
params.expect(provider: :id) | ||
end | ||
|
||
def provider_scope | ||
@provider_scope ||= if Current.user.is_admin? | ||
Provider.all | ||
else | ||
Current.user.providers | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= form_for :provider , url: provider_settings_path, method: :put, data: { controller: "topics", topics_target: "chooseForm", turbo_frame: "topics", turbo_action: "advance" } do |f| %> | ||
<div class="form-body"> | ||
<div class="row"> | ||
<div class="col-md-6 col-12"> | ||
<div class="form-group"> | ||
<%= f.label :provider %> | ||
<%= f.select :id, options_from_collection_for_select(providers, :id, :name), { prompt: "Change provider" }, class: "form-select", data: { action: "change->topics#chooseProvider" } %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "rails_helper" | ||
|
||
describe "Settings", type: :request do | ||
describe "PUT /settings/provider" do | ||
let(:user) { create(:user) } | ||
let(:provider) { create(:provider) } | ||
|
||
before { sign_in(user) } | ||
|
||
context "when provider cannot be found" do | ||
it "does not update current provider" do | ||
put provider_settings_url, params: { provider: { id: provider.id } } | ||
|
||
expect(response).to have_http_status(:not_found) | ||
end | ||
end | ||
|
||
context "when user has access to provider" do | ||
before do | ||
user.providers << provider | ||
end | ||
|
||
it "updates current provider" do | ||
put provider_settings_url, params: { provider: { id: provider.id } } | ||
|
||
signed_cookies = ActionDispatch::Request.new(Rails.application.env_config).cookie_jar | ||
|
||
expect(response).to redirect_to(root_url) | ||
expect(signed_cookies.signed[:current_provider_id]).to eq(provider.id) | ||
end | ||
end | ||
end | ||
end |