diff options
author | Ciro Santilli <ciro.santilli@gmail.com> | 2014-06-26 11:49:14 +0400 |
---|---|---|
committer | Ciro Santilli <ciro.santilli@gmail.com> | 2014-07-18 00:47:16 +0400 |
commit | 714f7201d3362793d11f33793e5ef6dc83bdd2f0 (patch) | |
tree | 54e6a4cc5ef89e132a123231b439b83de0e54d54 /spec | |
parent | b634d2801e6abdd039447f53ec5d9cf709f66b06 (diff) |
Add project stars.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 13 | ||||
-rw-r--r-- | spec/support/login_helpers.rb | 2 |
4 files changed, 46 insertions, 1 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 944df5314bd..c7a48898c56 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -2,6 +2,7 @@ require('spec_helper') describe ProjectsController do let(:project) { create(:project) } + let(:public_project) { create(:project, :public) } let(:user) { create(:user) } let(:jpg) { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') } let(:txt) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') } @@ -40,4 +41,17 @@ describe ProjectsController do end end end + + describe "POST #toggle_star" do + it "increases star count if user is signed in" do + sign_in(user) + post :toggle_star, id: public_project.to_param + expect(public_project.star_count).to eq(1) + end + + it "does nothing if user is not signed in" do + post :toggle_star, id: public_project.to_param + expect(public_project.star_count).to eq(0) + end + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index c3263ed0fe7..c2ebfbd9229 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -240,4 +240,22 @@ describe Project do it { project.open_branches.map(&:name).should include('bootstrap') } it { project.open_branches.map(&:name).should_not include('master') } end + + describe "#count_star" do + it "counts stars" do + user1 = create :user + user2 = create :user + project = create :project, :public + + expect(project.star_count).to eq(0) + user1.toggle_star(project) + expect(project.star_count).to eq(1) + user2.toggle_star(project) + expect(project.star_count).to eq(2) + user1.toggle_star(project) + expect(project.star_count).to eq(1) + user2.toggle_star(project) + expect(project.star_count).to eq(0) + end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a36b57a95de..b6ffb6ac24b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -355,4 +355,17 @@ describe User do expect(user.short_website_url).to eq 'test.com' end end + + describe "#toggle_star" do + it "toggles stars" do + user = create :user + project = create :project, :public + + expect(user.starred?(project)).to be_false + user.toggle_star(project) + expect(user.starred?(project)).to be_true + user.toggle_star(project) + expect(user.starred?(project)).to be_false + end + end end diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb index 7713e9f17d7..88e4d0419cb 100644 --- a/spec/support/login_helpers.rb +++ b/spec/support/login_helpers.rb @@ -20,6 +20,6 @@ module LoginHelpers end def logout - click_link "Logout" rescue nil + page.find(:css, ".icon-signout").click rescue nil end end |