Files
libr-2/spec/controllers/api/v1/posts_controller_spec.rb
2015-08-27 23:41:35 +08:00

45 lines
1.3 KiB
Ruby

require 'rails_helper'
RSpec.describe Api::V1::PostsController, type: :controller do
render_views
let(:json) { JSON.parse(response.body) }
before do
@current_user = User.create! email: 'test@librme.com', password: 'password'
print @current_user
request.headers.merge!('Authorization' => @current_user.active_auth_token)
end
describe "GET #create" do
it "should create article successfully" do
post :create, url: 'baidu.com', type: 'article', description: 'interesting website'
expect(response.status).to eq(200)
end
it "should create page successfully" do
post :create, url: 'baidu.com', type: 'page', description: 'interesting website'
expect(response.status).to eq(200)
end
it 'should return error when type is not allowed' do
post :create, url: 'baidu.com', type: 'Fake', description: 'interesting website'
expect(response.status).to eq(400)
end
end
describe "GET #list" do
it "returns http success" do
post = Post.find_or_create_by!(url: 'http://librme.com', type: 'Article')
@current_user.share_instances.create! sharable: post, description: 'this is description'
get :index
expect(response).to have_http_status(:success)
expect(JSON.parse(response.body).length).to eq(1)
end
end
end