diff --git a/spec/controllers/v1/collections_controller_spec.rb b/spec/controllers/v1/collections_controller_spec.rb index fc1eeaedc20f4ca214620bf4bd7a176c7a624a2f..d5621cd6e5cff9f368b01e9667624c7dae5ce27b 100644 --- a/spec/controllers/v1/collections_controller_spec.rb +++ b/spec/controllers/v1/collections_controller_spec.rb @@ -1,29 +1,45 @@ require 'rails_helper' RSpec.describe V1::CollectionsController, type: :controller do - fixtures :applications + fixtures :all it { should use_before_action(:authenticate_user!) } it { should use_before_action(:set_collection) } it { should route(:get, '/v1/collections').to(action: :index) } - describe 'GET #index' do + describe 'sociable actions' do + it { should use_before_action(:authorize_sociable!) } + it { should use_before_action(:view_object!) } + it { should route(:post, '/v1/collections/1/like').to(action: :like, id: 1) } + it { should route(:delete, '/v1/collections/1/like').to(action: :unlike, id: 1) } - context 'when application is authenticated' do + describe 'POST #like' do before do auth_app applications(:test_app), @request - get :index + post :like, id: collections(:ufpr).id end - it { expect(response.content_type).to eq('application/json') } - it { expect(response).to have_http_status(:ok) } + context 'when user is authenticated' do + it do + #user = applications(:test_app).user + expect(response).to have_http_status(:created) + end + end + + context 'when user is not authenticated' do + it { expect(response).to have_http_status(:unauthorized) } + end end + end - context 'when application is not authenticated' do - before { get :index } + describe 'GET #index' do + before do + auth_app applications(:test_app), @request + get :index + end - it { expect(response).to have_http_status(:unauthorized) } - end + it { expect(response.content_type).to eq('application/json') } + it { expect(response).to have_http_status(:ok) } end end \ No newline at end of file