Commit 714f7201 authored by Ciro Santilli's avatar Ciro Santilli
Browse files

Add project stars.

parent 36ff27371c93
......@@ -9,6 +9,11 @@ module SharedUser
user_exists("Mary Jane", {username: "mary_jane"})
end
step "I delete my account" do
visit profile_account_path
click_link "Delete account"
end
protected
def user_exists(name, options = {})
......
......@@ -2,6 +2,7 @@
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 @@
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
......@@ -240,4 +240,22 @@
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
......@@ -355,4 +355,17 @@
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
......@@ -20,6 +20,6 @@ def login_with(user)
end
def logout
click_link "Logout" rescue nil
page.find(:css, ".icon-signout").click rescue nil
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