docbrown/spec/requests/comments_api_spec.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

22 lines
713 B
Ruby

# http://localhost:3000/api/comments?a_id=23
require "rails_helper"
RSpec.describe "ArticlesApi", type: :request do
let(:article) { create(:article) }
before do
FactoryBot.create(:comment, commentable_type: "Article", commentable_id: article.id)
FactoryBot.create(:comment, commentable_type: "Article", commentable_id: article.id)
end
describe "GET /api/comments" do
it "returns not found if inproper article id" do
expect { get "/api/comments?a_id=gobbledygook" }.to raise_error(ActiveRecord::RecordNotFound)
end
it "returns comments for article passed" do
get "/api/comments?a_id=#{article.id}"
expect(JSON.parse(response.body).size).to eq(2)
end
end
end