Home Rspec fail: Node must be of the association's class when model is specified
Reply: 0

Rspec fail: Node must be of the association's class when model is specified

user1960
1#
user1960 Published in August 15, 2018, 5:36 am

I'm working on an application and during rspec of one controller I got the error Node must be of the association's class when model is specified The error point to the helper where I have element.form = form I'm using Neo4j as DB and Rails 4 for the app. The actual error occurs only when the test does the next method:

it "clears elements" do
      allow_any_instance_of(Study::Form).to receive(:link)

      version = StudyHelpers.create_study_version
      visit = StudyHelpers.create_study_form({}, version)
      form = StudyHelpers.create_study_visit({}, version)

      e = StudyHelpers.create_study_element({}, version, visit, form)
      e = StudyHelpers.create_study_element({}, version, visit, form)
      e = StudyHelpers.create_study_element({}, version, visit, form)

      expect(Study::Element.all.to_a.count).to eq(3)
      expect(Study::Visit.all.to_a.count).to eq(1)
      expect(Study::Form.all.to_a.count).to eq(1)

      request.env['HTTP_ACCEPT'] = "application/json"

      put :clear, {element: {version_uuid: version.id}, visit_id: {visit_id: visit.id, type: :HAS_VISIT}, form_id: {form_id: form.id, type: :HAS_FORM}}

      expect(response.content_type).to eq("application/json")
      expect(response.code).to eq("200")
      expect(Study::Element.all.to_a.count).to eq(0)
      expect(Study::Visit.all.to_a.count).to eq(1)
      expect(Study::Form.all.to_a.count).to eq(1)
    end

I don't know what the error means and how to resolve. My test spec complete: https://pastebin.com/QyiMy55G

The Helper:

def self.create_study_element(params={}, version, visit, form)
    params[:version_uuid] ||= version.uuid
    params[:used] ||= true
    element = Study::Element.create(params)
    element.form = form
    element.visit = visit
    return element
  end

The controller I'm testing: https://pastebin.com/W33RfSsE

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.295641 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO