Commit 9d6ffcfa authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor star btn logic for non-logged in user and fix tests

parent 405f91d2
...@@ -80,17 +80,17 @@ module ProjectsHelper ...@@ -80,17 +80,17 @@ module ProjectsHelper
@project.milestones.active.order("due_date, title ASC") @project.milestones.active.order("due_date, title ASC")
end end
def link_to_toggle_star(title, starred, signed_in) def link_to_toggle_star(title, starred)
cls = 'star-btn btn btn-sm btn-default' cls = 'star-btn btn btn-sm btn-default'
cls << ' disabled' unless signed_in
toggle_html = content_tag('span', class: 'toggle') do toggle_text =
toggle_text = if starred if starred
' Unstar' ' Unstar'
else else
' Star' ' Star'
end end
toggle_html = content_tag('span', class: 'toggle') do
icon('star') + toggle_text icon('star') + toggle_text
end end
...@@ -106,12 +106,10 @@ module ProjectsHelper ...@@ -106,12 +106,10 @@ module ProjectsHelper
data: { type: 'json' } data: { type: 'json' }
} }
path = toggle_star_namespace_project_path(@project.namespace, @project)
content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do
link_to( link_to(path, link_opts) do
toggle_star_namespace_project_path(@project.namespace, @project),
link_opts
) do
toggle_html + ' ' + count_html toggle_html + ' ' + count_html
end end
end end
......
...@@ -17,8 +17,15 @@ ...@@ -17,8 +17,15 @@
.project-repo-buttons .project-repo-buttons
.inline.star.js-toggler-container{class: @show_star ? 'on' : ''} .inline.star.js-toggler-container{class: @show_star ? 'on' : ''}
- if current_user - if current_user
= link_to_toggle_star('Star this project.', false, true) = link_to_toggle_star('Star this project.', false)
= link_to_toggle_star('Unstar this project.', true, true) = link_to_toggle_star('Unstar this project.', true)
- else
= link_to new_user_session_path, class: 'btn star-btn has_tooltip', title: 'You must sign in to star a project' do
%span
= icon('star')
Star
%span.count
= @project.star_count
- unless @project.empty_repo? - unless @project.empty_repo?
- if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace - if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace
.inline.fork-buttons.prepend-left-10 .inline.fork-buttons.prepend-left-10
......
...@@ -13,7 +13,7 @@ Feature: Project Star ...@@ -13,7 +13,7 @@ Feature: Project Star
Given public project "Community" Given public project "Community"
And I visit project "Community" page And I visit project "Community" page
When I click on the star toggle button When I click on the star toggle button
Then The project has 0 stars Then I redirected to sign in page
@javascript @javascript
Scenario: Signed in users can toggle star Scenario: Signed in users can toggle star
......
...@@ -22,12 +22,16 @@ class Spinach::Features::ProjectStar < Spinach::FeatureSteps ...@@ -22,12 +22,16 @@ class Spinach::Features::ProjectStar < Spinach::FeatureSteps
# Requires @javascript # Requires @javascript
step "I click on the star toggle button" do step "I click on the star toggle button" do
find(".star .toggle", visible: true).click find(".star-btn", visible: true).click
end
step 'I redirected to sign in page' do
current_path.should == new_user_session_path
end end
protected protected
def has_n_stars(n) def has_n_stars(n)
expect(page).to have_css(".star .count", text: /^#{n}$/, visible: true) expect(page).to have_css(".star-btn .count", text: n, visible: true)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment