Skip to content

Commit

Permalink
Add some request tests for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
oojewale committed Apr 10, 2016
1 parent 6d1abb8 commit f0c8783
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 6 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion app/controllers/tokens_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class TokensController < ApplicationController

class TokensController < ApplicationController
before_action :set_token, only: [:validate]
skip_before_action :authenticate_user, only: [:validate]

Expand Down
3 changes: 3 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions spec/requests/tags_request_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/support/create_resource.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/support/json_parser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def parsed_json
def body
response.body
end

def status
response.status
end
end


Expand Down

0 comments on commit f0c8783

Please sign in to comment.