diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e45a792f3..cf2758b78 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -94,7 +94,6 @@ var initialize_modules = function() { App.LegislationAnnotatable.initialize(); App.WatchFormChanges.initialize(); App.TreeNavigator.initialize(); - App.Followable.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/followable.js.coffee b/app/assets/javascripts/followable.js.coffee index 69ea61bac..762dfc041 100644 --- a/app/assets/javascripts/followable.js.coffee +++ b/app/assets/javascripts/followable.js.coffee @@ -1,9 +1,5 @@ App.Followable = - initialize: -> - $('.followable-content a[data-toggle]').on 'click', (event) -> - event.preventDefault() - update: (followable_id, button) -> $("#" + followable_id + " .js-follow").html(button) # Temporary line. Waiting for issue resolution: https://github.com/consul/consul/issues/1736 diff --git a/app/helpers/followables_helper.rb b/app/helpers/followables_helper.rb index 974270b0a..b1e1e83d3 100644 --- a/app/helpers/followables_helper.rb +++ b/app/helpers/followables_helper.rb @@ -8,17 +8,8 @@ module FollowablesHelper current_user && followed?(followable) end - def entity_title(title) - t("activerecord.models.#{title.underscore}.other") - end - - def followable_full_name(followable) - followable.class.name.parameterize - end - - def followable_title(followable) - entity = followable.class.name.underscore - t('shared.followable_title', entity: t("activerecord.models.#{entity}.one").downcase) + def followable_type_title(followable_type) + t("activerecord.models.#{followable_type.underscore}.other") end def followable_icon(followable) diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index c10fba678..b3426df12 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -10,32 +10,4 @@ module FollowsHelper t('shared.unfollow_entity', entity: t("activerecord.models.#{entity}.one").downcase) end - def follow_link_wrapper_id(followable) - "follow-expand-#{followable_full_name(followable)}-#{followable.id}" - end - - def unfollow_link_wrapper_id(followable) - "unfollow-expand-#{followable_full_name(followable)}-#{followable.id}" - end - - def follow_link_id(followable) - "follow-#{followable_full_name(followable)}-#{followable.id}" - end - - def unfollow_link_id(followable) - "unfollow-#{followable_full_name(followable)}-#{followable.id}" - end - - def follow_drop_id(followable) - "follow-drop-#{followable_full_name(followable)}-#{followable.id}" - end - - def unfollow_drop_id(followable) - "unfollow-drop-#{followable_full_name(followable)}-#{followable.id}" - end - - def entity_title(title) - t("activerecord.models.#{title.underscore}.other") - end - end diff --git a/app/views/follows/_followable_button.html.erb b/app/views/follows/_followable_button.html.erb index 7fc7a6ead..e96f1e179 100644 --- a/app/views/follows/_followable_button.html.erb +++ b/app/views/follows/_followable_button.html.erb @@ -3,41 +3,23 @@ <% if show_follow_action? followable %> - <%= link_to "##{follow_link_wrapper_id(followable)}", - id: follow_link_wrapper_id(followable), + <%= link_to t('shared.follow'), + follows_path(followable_id: followable.id, + followable_type: followable.class.name), + method: :post, remote: true, title: follow_text(followable), - data: { toggle: follow_drop_id(followable) }, - class: 'button hollow' do %> - <%= t('shared.follow') %> - <% end %> - + class: 'button hollow' %> <% end %> <% if show_unfollow_action? followable %> <% follow = followable.follows.where(user: current_user).first %> - <%= link_to "##{unfollow_link_wrapper_id(followable)}", - id: unfollow_link_wrapper_id(followable), + <%= link_to t('shared.unfollow'), + follow_path(follow), + method: :delete, remote: true, title: unfollow_text(followable), - data: { toggle: unfollow_drop_id(followable) }, - class: 'button hollow' do %> - <%= t('shared.unfollow') %> - <% end %> - + class: 'button hollow' %> <% end %> diff --git a/app/views/users/_following.html.erb b/app/views/users/_following.html.erb index 2d24f688f..a5e78a3b6 100644 --- a/app/views/users/_following.html.erb +++ b/app/views/users/_following.html.erb @@ -9,7 +9,7 @@ - <%= entity_title(followable_type) %> + <%= followable_type_title(followable_type) %> diff --git a/spec/shared/features/followable.rb b/spec/shared/features/followable.rb index 7285ee15f..7c738c8a3 100644 --- a/spec/shared/features/followable.rb +++ b/spec/shared/features/followable.rb @@ -41,16 +41,15 @@ shared_examples "followable" do |followable_class_name, followable_path, followa expect(page).to have_link("Follow") end - scenario "Should display unfollow button when click on follow button", :js do + scenario "Should display unfollow after user clicks on follow button", :js do user = create(:user) login_as(user) visit send(followable_path, arguments) within "##{dom_id(followable)}" do click_link "Follow" - page.find("#follow-#{followable_dom_name}-#{followable.id}").click - expect(page).to have_css("#unfollow-expand-#{followable_dom_name}-#{followable.id}") + expect(page).to have_link "Unfollow" end end @@ -64,7 +63,7 @@ shared_examples "followable" do |followable_class_name, followable_path, followa expect(page).to have_link("Unfollow") end - scenario "Should display follow button when click on unfollow button", :js do + scenario "Should display follow button after user clicks on unfollow button", :js do user = create(:user) follow = create(:follow, user: user, followable: followable) login_as(user) @@ -72,9 +71,8 @@ shared_examples "followable" do |followable_class_name, followable_path, followa visit send(followable_path, arguments) within "##{dom_id(followable)}" do click_link "Unfollow" - page.find("#unfollow-#{followable_dom_name}-#{followable.id}").click - expect(page).to have_css("#follow-expand-#{followable_dom_name}-#{followable.id}") + expect(page).to have_link "Follow" end end