Sha256: a3e18cffe4727decaaa115a065f27d48baf3295ae04b2883828a2dc6a682f4f1

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe ActiveRecordSurveyApi::InstancesController, :type => :controller, :instances_api => true do
	routes { ActiveRecordSurveyApi::Engine.routes }

	before(:each) do
		I18n.locale = :en
	end

	describe 'CREATE' do
		it 'should create a new instance' do
			survey = FactoryGirl.build(:basic_survey)
			survey.save

			request.headers[:HTTP_ACCEPT_LANGUAGE] = "en"
			header_params = {
				:survey_id => survey.id,
				:HTTP_ACCEPT_LANGUAGE => 'en',
				:CONTENT_TYPE => 'application/json',
				:ACCEPT => 'application/json'
			}

			post :create,
			{
			}.to_json, header_params
		end
	end

	describe 'PUT update/:id' do
		it 'should bulk update instance responses' do
			survey = FactoryGirl.build(:basic_survey)
			survey.save

			request.headers[:HTTP_ACCEPT_LANGUAGE] = "en"
			header_params = {
				:survey_id => survey.id,
				:HTTP_ACCEPT_LANGUAGE => 'en',
				:CONTENT_TYPE => 'application/json',
				:ACCEPT => 'application/json'
			}

			# Create the instance
			post :create,
			{
			}.to_json, header_params

			json_body = JSON.parse(response.body)

			header_params[:id] = json_body["data"]["id"].to_i

			put :update,
			{
				:instance => {
					:instance_nodes_attributes => [
						{ :active_record_survey_node_id => 2 },
						{ :active_record_survey_node_id => 4 },
						{ :active_record_survey_node_id => 7 },
					]
				}
			}.to_json, header_params
			json_body = JSON.parse(response.body)

			put :update,
			{
				:instance => {
					:instance_nodes_attributes => [
						{ :active_record_survey_node_id => 5 },
						{ :active_record_survey_node_id => 7 },
					]
				}
			}.to_json, header_params
			json_body = JSON.parse(response.body)

			put :update,
			{
				:instance => {
					:instance_nodes_attributes => [
						{ :active_record_survey_node_id => 11 },
						{ :active_record_survey_node_id => 12 },
						{ :active_record_survey_node_id => 8 },
					]
				}
			}.to_json, header_params
			json_body = JSON.parse(response.body)

		end
	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_record_survey_api-0.0.19 spec/controllers/active_record_survey_api/surveys/instances_spec.rb
active_record_survey_api-0.0.18 spec/controllers/active_record_survey_api/surveys/instances_spec.rb
active_record_survey_api-0.0.17 spec/controllers/active_record_survey_api/surveys/instances_spec.rb
active_record_survey_api-0.0.14 spec/controllers/active_record_survey_api/surveys/instances_spec.rb
active_record_survey_api-0.0.12 spec/controllers/active_record_survey_api/surveys/instances_spec.rb
active_record_survey_api-0.0.11 spec/controllers/active_record_survey_api/surveys/instances_spec.rb