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

This commit is contained in:
Dmitriy Zaporozhets 2015-03-29 18:50:45 -07:00
parent 405f91d2b8
commit 9d6ffcfa5f
4 changed files with 26 additions and 17 deletions

View file

@ -80,17 +80,17 @@ module ProjectsHelper
@project.milestones.active.order("due_date, title ASC")
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 << ' disabled' unless signed_in
toggle_text =
if starred
' Unstar'
else
' Star'
end
toggle_html = content_tag('span', class: 'toggle') do
toggle_text = if starred
' Unstar'
else
' Star'
end
icon('star') + toggle_text
end
@ -106,12 +106,10 @@ module ProjectsHelper
data: { type: 'json' }
}
path = toggle_star_namespace_project_path(@project.namespace, @project)
content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do
link_to(
toggle_star_namespace_project_path(@project.namespace, @project),
link_opts
) do
link_to(path, link_opts) do
toggle_html + ' ' + count_html
end
end

View file

@ -17,8 +17,15 @@
.project-repo-buttons
.inline.star.js-toggler-container{class: @show_star ? 'on' : ''}
- if current_user
= link_to_toggle_star('Star this project.', false, true)
= link_to_toggle_star('Unstar this project.', true, true)
= link_to_toggle_star('Star this project.', false)
= 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?
- if current_user && can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace
.inline.fork-buttons.prepend-left-10

View file

@ -13,7 +13,7 @@ Feature: Project Star
Given public project "Community"
And I visit project "Community" page
When I click on the star toggle button
Then The project has 0 stars
Then I redirected to sign in page
@javascript
Scenario: Signed in users can toggle star

View file

@ -22,12 +22,16 @@ class Spinach::Features::ProjectStar < Spinach::FeatureSteps
# Requires @javascript
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
protected
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