diff --git a/.DS_Store b/.DS_Store index 4f9fb81..2e0f583 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/app/controllers/tokens_controller.rb b/app/controllers/tokens_controller.rb index 56ea174..c13a374 100644 --- a/app/controllers/tokens_controller.rb +++ b/app/controllers/tokens_controller.rb @@ -1,4 +1,5 @@ -class TokensController < ApplicationController + + class TokensController < ApplicationController before_action :set_token, only: [:validate] skip_before_action :authenticate_user, only: [:validate] diff --git a/db/schema.rb b/db/schema.rb index 3dc5a1f..b6c1f50 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,6 +17,7 @@ t.integer "user_id" t.integer "question_id" t.string "content" + t.integer "votes" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "comments_count", default: 0 @@ -26,6 +27,7 @@ create_table "comments", force: :cascade do |t| t.integer "user_id" t.string "content" + t.integer "votes" t.integer "comment_on_id" t.string "comment_on_type" t.datetime "created_at", null: false @@ -38,6 +40,7 @@ t.integer "user_id" t.string "title" t.string "content" + t.integer "votes" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "views", default: 0 diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 5dd66d0..cd2535a 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -4,9 +4,7 @@ let(:arg) { :recent } let(:tag_name) { "Amity" } before :each do - 5.times { create(:tag, name: "Contract", created_at: 4.days.ago) } - 3.times { create(:tag, name: "Amity", created_at: 2.days.ago) } - 2.times { create(:tag, name: "Kaizen") } + create_tags end describe ".get_tags_that_are" do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d4f1923..3768ce1 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,8 +12,8 @@ require "shoulda/matchers" require "spec_helper" require "rspec/rails" -require 'coveralls' -Coveralls.wear! +# require 'coveralls' +# Coveralls.wear! # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/requests/tags_request_spec.rb b/spec/requests/tags_request_spec.rb new file mode 100644 index 0000000..57a682a --- /dev/null +++ b/spec/requests/tags_request_spec.rb @@ -0,0 +1,42 @@ +require 'rails_helper' + +RSpec.describe TagsController, type: :request do + + let(:user) { valid_user } + before :each do + create_tags + end + + describe "GET /tags/popular" do + it "returns 200 status and popular tags" do + + get popular_tags_path, {format: :json}, authorization_header + + expect(parsed_json).to have_key("contract") + expect(status).to eq 200 + end + end + + describe "GET /tags/recent" do + it "returns 200 status and recent tags" do + + get recent_tags_path, {format: :json}, authorization_header + + expect(parsed_json.first["id"]).to eq(Tag.last.id) + expect(parsed_json.last["id"]).to eq(Tag.first.id) + expect(parsed_json.count).to eq(Tag.count) + expect(status).to eq 200 + end + end + + describe "GET /tags/trending" do + it "returns 200 status and trending tags" do + + get trending_tags_path, {format: :json}, authorization_header + + expect(parsed_json.first.last).to eq(parsed_json.values.max) + expect(status).to eq 200 + end + end + +end \ No newline at end of file diff --git a/spec/support/create_resource.rb b/spec/support/create_resource.rb new file mode 100644 index 0000000..5aec849 --- /dev/null +++ b/spec/support/create_resource.rb @@ -0,0 +1,11 @@ +module CreateResource + def create_tags + 5.times { create(:tag, name: "Contract", created_at: 4.days.ago) } + 3.times { create(:tag, name: "Amity", created_at: 2.days.ago) } + 2.times { create(:tag, name: "Kaizen") } + end +end + +RSpec.configure do |config| + config.include CreateResource +end \ No newline at end of file diff --git a/spec/support/json_parser_helper.rb b/spec/support/json_parser_helper.rb index 8ecf61b..8e5f5c7 100644 --- a/spec/support/json_parser_helper.rb +++ b/spec/support/json_parser_helper.rb @@ -6,6 +6,10 @@ def parsed_json def body response.body end + + def status + response.status + end end