Skip to content

Commit

Permalink
improve&optimize edit topic url logic (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
morr committed Oct 23, 2017
1 parent cd80dc1 commit 0a1e13f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def new
end

def edit
ensure_redirect! @topic_view.urls.edit_url if params[:action] == 'edit'
end

def create
Expand Down Expand Up @@ -136,7 +137,7 @@ def topic_params
def set_view
@forums_view = Forums::View.new params[:forum]

if params[:action] == 'show' && @resource
if %w[show edit].include?(params[:action]) && @resource
@topic_view = Topics::TopicViewFactory.new(false, false).build @resource
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/view_objects/topics/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def edit_url
elsif topic_type_policy.collection_topic?
h.edit_collection_url topic.linked

elsif topic_type_policy.club_page_topic?
h.edit_club_club_page_path topic.linked.club, topic.linked

else
h.edit_topic_url topic
end
Expand Down
2 changes: 1 addition & 1 deletion app/view_objects/topics/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def cache_key
# т.к. эти методы могут быть переопределены в наследниках
@is_preview,
@is_mini,
:v9
:v10
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/topics/_buttons.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ aside.buttons
data-dynamic='authorized'
]
a.item-edit.short[
href=topic_view.urls.edit_url
href=edit_topic_url(topic_view.topic)
data-text=t('actions.edit')
title=t('actions.edit')
]
Expand Down
14 changes: 12 additions & 2 deletions spec/controllers/topics_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,18 @@

context 'authenticated' do
before { sign_in user }
before { get :edit, params: { id: topic.id } }
it { expect(response).to have_http_status :success }
before { get :edit, params: { id: topic.to_param } }

context 'allowed edit url' do
it { expect(response).to have_http_status :success }
end

context 'disallowed edit url' do
let!(:topic) { create :collection_topic, user: user, linked: collection }
let(:collection) { create :collection, user: user }

it { expect(response).to redirect_to edit_collection_url(collection) }
end
end
end

Expand Down

0 comments on commit 0a1e13f

Please sign in to comment.