Skip to content

Commit

Permalink
[#10]Standardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmckissock committed Jun 27, 2024
1 parent e6efc31 commit cf877db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

gem 'sassc-rails'
gem "sassc-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def show
def upvote
vote(1)
respond_to do |format|
format.json { render json: { new_score: @article.score } }
format.json { render json: {new_score: @article.score} }
end
end

def downvote
vote(-1)
respond_to do |format|
format.json { render json: { new_score: @article.score } }
format.json { render json: {new_score: @article.score} }
end
end

Expand Down
54 changes: 27 additions & 27 deletions spec/controllers/articles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@
end

describe "POST #upvote" do
it "sets vote value to 1 if user has not voted" do
expect {
post :upvote, params: {id: article.id}, format: :json
}.to change { article.votes.count }.by(1)
expect(article.reload.votes.last.value).to eq(1)
end
it "sets vote value to 1 if user has not voted" do
expect {
post :upvote, params: {id: article.id}, format: :json
}.to change { article.votes.count }.by(1)
expect(article.reload.votes.last.value).to eq(1)
end

it "sets vote value to 0 if user has already upvoted" do
create(:vote, votable: article, user: user, value: 1)
expect {
post :upvote, params: {id: article.id}, format: :json
}.not_to change { article.votes.count }
expect(article.reload.votes.last.value).to eq(0)
it "sets vote value to 0 if user has already upvoted" do
create(:vote, votable: article, user: user, value: 1)
expect {
post :upvote, params: {id: article.id}, format: :json
}.not_to change { article.votes.count }
expect(article.reload.votes.last.value).to eq(0)
end
end
end

describe "POST #downvote" do
it "sets vote value to -1 if user has not already downvoted" do
expect {
post :downvote, params: {id: article.id}, format: :json
}.to change { article.votes.count }.by(1)
expect(article.reload.votes.last.value).to eq(-1)
end
describe "POST #downvote" do
it "sets vote value to -1 if user has not already downvoted" do
expect {
post :downvote, params: {id: article.id}, format: :json
}.to change { article.votes.count }.by(1)
expect(article.reload.votes.last.value).to eq(-1)
end

it "sets vote value to 0 if user has already downvoted" do
create(:vote, votable: article, user: user, value: -1)
expect {
post :downvote, params: {id: article.id}, format: :json
}.not_to change { article.votes.count }
expect(article.reload.votes.last.value).to eq(0)
it "sets vote value to 0 if user has already downvoted" do
create(:vote, votable: article, user: user, value: -1)
expect {
post :downvote, params: {id: article.id}, format: :json
}.not_to change { article.votes.count }
expect(article.reload.votes.last.value).to eq(0)
end
end
end
end
end

0 comments on commit cf877db

Please sign in to comment.