diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-29 18:50:45 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-29 18:50:45 -0700 |
commit | 9d6ffcfa5f09608d81031c7e366470b9c8a46db8 (patch) | |
tree | 03f25e79adbfcdd405c82eb9a269ee1578c41a6b | |
parent | 405f91d2b8eb7c8276341ac44fcabc758fc89343 (diff) | |
download | gitlab-ce-9d6ffcfa5f09608d81031c7e366470b9c8a46db8.tar.gz |
Refactor star btn logic for non-logged in user and fix tests
-rw-r--r-- | app/helpers/projects_helper.rb | 22 | ||||
-rw-r--r-- | app/views/projects/_home_panel.html.haml | 11 | ||||
-rw-r--r-- | features/project/star.feature | 2 | ||||
-rw-r--r-- | features/steps/project/star.rb | 8 |
4 files changed, 26 insertions, 17 deletions
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 4629de2ecad..e3734023be3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -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_html = content_tag('span', class: 'toggle') do - toggle_text = if starred - ' Unstar' - else - ' Star' - end + toggle_text = + if starred + ' Unstar' + else + ' Star' + end + toggle_html = content_tag('span', class: 'toggle') do 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 diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index 774be6cd138..5689bdee1c6 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -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 diff --git a/features/project/star.feature b/features/project/star.feature index 3322f891805..a45f9c470ea 100644 --- a/features/project/star.feature +++ b/features/project/star.feature @@ -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 diff --git a/features/steps/project/star.rb b/features/steps/project/star.rb index ae2e4c7a201..50cdfd73c34 100644 --- a/features/steps/project/star.rb +++ b/features/steps/project/star.rb @@ -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 |