spec/controllers/landable/api/audits_controller_spec.rb in landable-1.13.1 vs spec/controllers/landable/api/audits_controller_spec.rb in landable-1.13.2
- old
+ new
@@ -1,148 +1,150 @@
require 'spec_helper'
-module Landable::Api
- describe AuditsController, json: true do
- routes { Landable::Engine.routes }
+module Landable
+ module Api
+ describe AuditsController, json: true do
+ routes { Landable::Engine.routes }
- let(:page) { create :page }
- let(:template) { create :template }
+ let(:page) { create :page }
+ let(:template) { create :template }
- describe '#index' do
- context 'all' do
- include_examples 'Authenticated API controller', :make_request
+ describe '#index' do
+ context 'all' do
+ include_examples 'Authenticated API controller', :make_request
- let(:audits) { create_list :audit, 3 }
+ let(:audits) { create_list :audit, 3 }
- def make_request(params = {})
- get :index
- end
+ def make_request(_params = {})
+ get :index
+ end
- it 'renders audits as json' do
- make_request
- last_json['audits'].collect { |p| p['id'] }.sort.should == Landable::Audit.all.map(&:id).sort
+ it 'renders audits as json' do
+ make_request
+ last_json['audits'].collect { |p| p['id'] }.sort.should eq Landable::Audit.all.map(&:id).sort
+ end
end
- end
- context 'tempalte audits' do
- include_examples 'Authenticated API controller', :make_request
+ context 'tempalte audits' do
+ include_examples 'Authenticated API controller', :make_request
- let(:audits) { create_list :audit, 3, auditable_id: template.id, auditable_type: 'Landable::Template', approver: 'ME!!!' }
+ let(:audits) { create_list :audit, 3, auditable_id: template.id, auditable_type: 'Landable::Template', approver: 'ME!!!' }
- def make_request(params = {})
- get :index, auditable_id: template.id
- end
+ def make_request(_params = {})
+ get :index, auditable_id: template.id
+ end
- it 'renders audits as json' do
- make_request
- last_json['audits'].collect { |p| p['id'] }.sort.should == Landable::Audit.all.map(&:id).sort
+ it 'renders audits as json' do
+ make_request
+ last_json['audits'].collect { |p| p['id'] }.sort.should eq Landable::Audit.all.map(&:id).sort
+ end
end
- end
- context 'page audits' do
- include_examples 'Authenticated API controller', :make_request
+ context 'page audits' do
+ include_examples 'Authenticated API controller', :make_request
- let(:audits) { create_list :audit, 3, auditable_id: page.id, auditable_type: 'Landable::Page', approver: 'ME!!!' }
+ let(:audits) { create_list :audit, 3, auditable_id: page.id, auditable_type: 'Landable::Page', approver: 'ME!!!' }
- def make_request(params = {})
- get :index, auditable_id: page.id
- end
+ def make_request(_params = {})
+ get :index, auditable_id: page.id
+ end
- it 'renders audits as json' do
- make_request
- last_json['audits'].collect { |p| p['id'] }.sort.should == Landable::Audit.all.map(&:id).sort
+ it 'renders audits as json' do
+ make_request
+ last_json['audits'].collect { |p| p['id'] }.sort.should eq Landable::Audit.all.map(&:id).sort
+ end
end
end
- end
- describe '#show' do
- include_examples 'Authenticated API controller', :make_request
- let(:audit) { create(:audit) }
-
- def make_request(id = audit.id)
- get :show, id: id
- end
-
- it 'renders the page as JSON' do
- make_request
- last_json['audit']['flags'].should == audit.flags
- end
-
- context 'no such page' do
- it 'returns 404' do
- make_request random_uuid
- response.status.should == 404
- end
- end
- end
-
- describe '#create' do
- context 'template audit' do
+ describe '#show' do
include_examples 'Authenticated API controller', :make_request
+ let(:audit) { create(:audit) }
- let(:default_params) do
- { audit: attributes_for(:audit).merge(auditable_id: template.id,
- auditable_type: 'Landable::Template',
- approver: 'Marley') }
+ def make_request(id = audit.id)
+ get :show, id: id
end
- let(:audit) do
- Landable::Audit.where(auditable_id: default_params[:audit][:auditable_id]).first
+ it 'renders the page as JSON' do
+ make_request
+ last_json['audit']['flags'].should eq audit.flags
end
- def make_request(params = {})
- post :create, default_params.deep_merge(audit: params, template_id: template.id)
+ context 'no such page' do
+ it 'returns 404' do
+ make_request random_uuid
+ response.status.should eq 404
+ end
end
+ end
- context 'success' do
- it 'returns 201 Created' do
- make_request
- response.status.should == 201
+ describe '#create' do
+ context 'template audit' do
+ include_examples 'Authenticated API controller', :make_request
+
+ let(:default_params) do
+ { audit: attributes_for(:audit).merge(auditable_id: template.id,
+ auditable_type: 'Landable::Template',
+ approver: 'Marley') }
end
- it 'returns header Location with the audit URL' do
- make_request
- response.headers['Location'].should == audit_url(audit)
+ let(:audit) do
+ Landable::Audit.where(auditable_id: default_params[:audit][:auditable_id]).first
end
- it 'renders the audit as JSON' do
- make_request
- last_json['audit']['flags'].should == audit.flags
+ def make_request(params = {})
+ post :create, default_params.deep_merge(audit: params, template_id: template.id)
end
- end
- end
- context 'page audit' do
- include_examples 'Authenticated API controller', :make_request
+ context 'success' do
+ it 'returns 201 Created' do
+ make_request
+ response.status.should eq 201
+ end
- let(:default_params) do
- { audit: attributes_for(:audit).merge(auditable_id: page.id,
- auditable_type: 'Landable::Page',
- approver: 'Marley') }
- end
+ it 'returns header Location with the audit URL' do
+ make_request
+ response.headers['Location'].should eq audit_url(audit)
+ end
- let(:audit) do
- Landable::Audit.where(auditable_id: default_params[:audit][:auditable_id]).first
+ it 'renders the audit as JSON' do
+ make_request
+ last_json['audit']['flags'].should eq audit.flags
+ end
+ end
end
- def make_request(params = {})
- post :create, default_params.deep_merge(page_audit: params, page_id: page.id)
- end
+ context 'page audit' do
+ include_examples 'Authenticated API controller', :make_request
- context 'success' do
- it 'returns 201 Created' do
- make_request
- response.status.should == 201
+ let(:default_params) do
+ { audit: attributes_for(:audit).merge(auditable_id: page.id,
+ auditable_type: 'Landable::Page',
+ approver: 'Marley') }
end
- it 'returns header Location with the audit URL' do
- make_request
- response.headers['Location'].should == audit_url(audit)
+ let(:audit) do
+ Landable::Audit.where(auditable_id: default_params[:audit][:auditable_id]).first
end
- it 'renders the audit as JSON' do
- make_request
- last_json['audit']['flags'].should == audit.flags
+ def make_request(params = {})
+ post :create, default_params.deep_merge(page_audit: params, page_id: page.id)
+ end
+
+ context 'success' do
+ it 'returns 201 Created' do
+ make_request
+ response.status.should eq 201
+ end
+
+ it 'returns header Location with the audit URL' do
+ make_request
+ response.headers['Location'].should eq audit_url(audit)
+ end
+
+ it 'renders the audit as JSON' do
+ make_request
+ last_json['audit']['flags'].should eq audit.flags
+ end
end
end
end
end
end