diff options
author | Ciro Santilli <ciro.santilli@gmail.com> | 2014-07-14 15:17:59 +0200 |
---|---|---|
committer | Ciro Santilli <ciro.santilli@gmail.com> | 2014-07-17 22:47:16 +0200 |
commit | 9b5c7a4d6026265cfeaeac9ad5101f8826515dbe (patch) | |
tree | 18d795d222563b9c672aff1121b11022a32016b7 /spec | |
parent | ecd771ccdfe54b08ea7f80f64667228b7938238d (diff) | |
download | gitlab-ce-9b5c7a4d6026265cfeaeac9ad5101f8826515dbe.tar.gz |
Add star count, view logic, more tests.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects_controller_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 52 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 27 |
3 files changed, 81 insertions, 9 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index c7a48898c56..71bc49787cc 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -43,15 +43,20 @@ describe ProjectsController do end describe "POST #toggle_star" do - it "increases star count if user is signed in" do + it "toggles star if user is signed in" do sign_in(user) + expect(user.starred?(public_project)).to be_false post :toggle_star, id: public_project.to_param - expect(public_project.star_count).to eq(1) + expect(user.starred?(public_project)).to be_true + post :toggle_star, id: public_project.to_param + expect(user.starred?(public_project)).to be_false 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) + expect(user.starred?(public_project)).to be_false + post :toggle_star, id: public_project.to_param + expect(user.starred?(public_project)).to be_false end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index c2ebfbd9229..72673a1f812 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -241,21 +241,61 @@ describe Project do it { project.open_branches.map(&:name).should_not include('master') } end - describe "#count_star" do - it "counts stars" do + describe "#star_count" do + it "counts stars from multiple users" 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) + expect(project.reload.star_count).to eq(1) + user2.toggle_star(project) - expect(project.star_count).to eq(2) + project.reload + expect(project.reload.star_count).to eq(2) + user1.toggle_star(project) - expect(project.star_count).to eq(1) + project.reload + expect(project.reload.star_count).to eq(1) + user2.toggle_star(project) - expect(project.star_count).to eq(0) + project.reload + expect(project.reload.star_count).to eq(0) + end + + it "counts stars on the right project" do + user = create :user + project1 = create :project, :public + project2 = create :project, :public + + expect(project1.star_count).to eq(0) + expect(project2.star_count).to eq(0) + + user.toggle_star(project1) + project1.reload + project2.reload + expect(project1.star_count).to eq(1) + expect(project2.star_count).to eq(0) + + user.toggle_star(project1) + project1.reload + project2.reload + expect(project1.star_count).to eq(0) + expect(project2.star_count).to eq(0) + + user.toggle_star(project2) + project1.reload + project2.reload + expect(project1.star_count).to eq(0) + expect(project2.star_count).to eq(1) + + user.toggle_star(project2) + project1.reload + project2.reload + expect(project1.star_count).to eq(0) + expect(project2.star_count).to eq(0) end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b6ffb6ac24b..ef6b8a94502 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -356,6 +356,33 @@ describe User do end end + describe "#starred?" do + it "determines if user starred a project" do + user = create :user + project1 = create :project, :public + project2 = create :project, :public + + expect(user.starred?(project1)).to be_false + expect(user.starred?(project2)).to be_false + + star1 = UsersStarProject.create!(project: project1, user: user) + expect(user.starred?(project1)).to be_true + expect(user.starred?(project2)).to be_false + + star2 = UsersStarProject.create!(project: project2, user: user) + expect(user.starred?(project1)).to be_true + expect(user.starred?(project2)).to be_true + + star1.destroy + expect(user.starred?(project1)).to be_false + expect(user.starred?(project2)).to be_true + + star2.destroy + expect(user.starred?(project1)).to be_false + expect(user.starred?(project2)).to be_false + end + end + describe "#toggle_star" do it "toggles stars" do user = create :user |