Como testar a postagem do Controller: criar JSON api nos trilhos usando rspec?

Eu rasguei meu cabelo tentando fazer o teste passar. Eu tenho uma API JSON que se parece com isso:

{
  "data": [
    {
      "id": "b99f8173-0492-457f-9de9-6c1d8d6832ed",
      "type": "manufacturer_organizations",
      "attributes": {
        "account_number": "random test 123"
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "fb20ddc9-a3ee-47c3-bdd2-f710541ff89c",
            "type": "organizations"
          }
        },
        "manufacturer": {
          "data": {
            "id": "1",
            "type": "manufacturers"
          }
        }
      }
    },...

Estou tentando fazer umapost :create teste em trilhos.

let!(:manufacturer_organization) {FactoryGirl.create(:manufacturer_organization)}
let(:manufacturer_organization2) { FactoryGirl.create(:manufacturer_organization)}

...

  describe "POST create" do
    it "posts a valid manufacturer organization data" do
      authenticate
      organization = FactoryGirl.create(:organization)
      manufacturer = FactoryGirl.create(:manufacturer)

      post :create, manufacturer_organization2.to_json #what should I put here instead?

      expect(json['data'].length).to eq(2)
    end

  #=> error: JSON::ParserError: A JSON text must at least contain two octets!

Tentei várias postagens SO isto, ist eEste artig

Aqui estão algumas das tentativas que eu tentei:

post :create, params: {organization_id: organization.id, manufacturer: manufacturer.id, account_number: "123 test account number"}
#=> error: JSON::ParserError:
   A JSON text must at least contain two octets!

o

post :create, params: :manufacturer_organization_2
#=> 
 NoMethodError:
   undefined method `symbolize_keys' for :manufacturer_organization_2:Symbol

o

json = { :format => 'json', :manufacturer_organization => { :account_number => "foo123", :organization_id => organization.id, :manufacturer_id => manufacturer.id } }
post :create, json
#=>  NoMethodError:
   undefined method `length' for nil:NilClass 

Como posso testar meu controlador para aceitarmanufacturer_id, organization_id, and account_number através dapost :create? No momento, o modo como eu testei é contar @ inicijson['data'].length (inicialmente 1); no final, esperojson['data'].length ser 2 após sucessopost :create. Como posso simular a criação de uma entrada válida manufacturer_organization?

Editar

Desculpe, esqueci de colocar o meu método json helper:

def json
  JSON.parse(response.body)
end

Este passe:

  describe "POST create" do
    it "posts a valid manufacturer organization data" do
      authenticate
      organization = FactoryGirl.create(:organization)
      manufacturer = FactoryGirl.create(:manufacturer)
      post :create, {account_number: "Test account numba", organization_id: organization.id, manufacturer_id: manufacturer.id}
      expect(response).to be_success
    end

enquanto adicionaexpect(json['success']).to eq("Yay!") me dá este erro:

JSON::ParserError: A JSON text must at least contain two octets!

Controlador

  def create
    @manufacturer_organization = ManufacturerOrganization.new(manufacturer_organization_params)
    if @manufacturer_organization.save
      puts "success!"
      render json: {success: "Yay!"}
    else
      puts "Sorry, something went wrong!"
    end
  end


def manufacturer_organization_params
    api_params.permit(:organization_id, :manufacturer_id, :account_number)
end

enquanto@api_params ||= ActionController::Parameters.new(ActiveModelSerializers::Deserialization.jsonapi_parse(params))

questionAnswers(1)

yourAnswerToTheQuestion