Skip to content

Commit d0ac74e

Browse files
dmitrytragerdcollie2
authored andcommitted
add topics_title helper and fix specs
1 parent ee3452c commit d0ac74e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

app/controllers/settings_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class SettingsController < ApplicationController
22
def provider
3-
provider = provider_scope.find_by(id: provider_params[:id])
3+
provider = provider_scope.find(provider_params[:id])
44
cookies.signed[:current_provider_id] = provider.id if provider
55
redirect_to request.referer || root_path
66
end

app/controllers/topics_controller.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def archive
4646
private
4747

4848
def other_available_providers
49-
return unless Current.user.providers.any?
49+
return [] unless Current.user.providers.any?
5050

5151
Current.user.providers.where.not(id: current_provider.id)
5252
end
@@ -69,8 +69,15 @@ def set_topic
6969
def scope
7070
@scope ||= if Current.user.is_admin?
7171
Topic.all
72-
else
72+
elsif current_provider.present?
7373
current_provider.topics
74+
else
75+
Current.user.topics
7476
end.includes(:language, :provider)
7577
end
78+
79+
def topics_title
80+
current_provider.present? ? "#{current_provider.name}/topics" : "Topics"
81+
end
82+
helper_method :topics_title
7683
end

app/views/topics/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<%= turbo_frame_tag "topics" do %>
88
<div class="card">
99
<div class="card-header d-flex justify-content-between align-items-center">
10-
<h2 class="card-title"><%= current_provider.name %>'s topics</h2>
10+
<h2 class="card-title"><%= topics_title %></h2>
1111
<%= link_to new_topic_path, class: "btn btn-primary" do %>
1212
<i class="bi bi-plus"></i> Add New Topic
1313
<% end %>

spec/requests/settings/provider_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
context "when provider cannot be found" do
1111
it "does not update current provider" do
12-
put provider_settings_url, params: { id: provider.id }
12+
put provider_settings_url, params: { provider: { id: provider.id } }
1313

1414
expect(response).to have_http_status(:not_found)
1515
end
@@ -21,7 +21,7 @@
2121
end
2222

2323
it "updates current provider" do
24-
put provider_settings_url, params: { id: provider.id }
24+
put provider_settings_url, params: { provider: { id: provider.id } }
2525

2626
signed_cookies = ActionDispatch::Request.new(Rails.application.env_config).cookie_jar
2727

0 commit comments

Comments
 (0)