Sha256: d0f3e37e5c74404f9180b9dc476c4b103ef3291e6aacfe9a36df206d44ddebbf

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'
require 'synchromesh/integration/test_components'
require 'reactive_record/factory'

describe "many to many associations", js: true do

  before(:each) do
    seed_database
  end

  before(:each) do
    # spec_helper resets the policy system after each test so we have to setup
    # before each test
    stub_const 'TestApplication', Class.new
    stub_const 'TestApplicationPolicy', Class.new
    TestApplicationPolicy.class_eval do
      regulate_all_broadcasts { |policy| policy.send_all }
      allow_change(to: :all, on: [:create, :update, :destroy]) { true }
    end
    size_window(:small, :portrait)
  end

  it "does not effect the base relationship count" do
    expect_promise do
      ReactiveRecord.load do
        TodoItem.find_by_title("a todo for mitch").comments.count
      end
    end.to be(1)
  end

  it "does not effect access to attributes in the base relationship" do
    expect_promise do
      ReactiveRecord.load do
        TodoItem.find_by_title("a todo for mitch").comments.count
      end.then do
        ReactiveRecord.load do
          TodoItem.find_by_title("a todo for mitch").comments.first.user.email
        end
      end
    end.to eq("adamg@catprint.com")
  end

  it "can be followed directly" do
    expect_promise do
      ReactiveRecord.load do
        TodoItem.find_by_title("a todo for mitch").commenters.first.email
      end
    end.to eq("adamg@catprint.com")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyper-mesh-0.4.0 spec/reactive_record/many_to_many_spec.rb