File: paths_spec.rb

package info (click to toggle)
ruby-joiner 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 188 kB
  • sloc: ruby: 303; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'spec_helper'

describe 'Paths' do
  describe 'Aggregations' do
    it "indicates aggregation for has many associations" do
      path = Joiner::Path.new User, [:articles]

      expect(path).to be_aggregate
    end

    it "indicates non-aggregation for belongs to association" do
      path = Joiner::Path.new Article, [:user]

      expect(path).to_not be_aggregate
    end

    it "indicates non-aggregation when the path is empty" do
      path = Joiner::Path.new Article, []

      expect(path).to_not be_aggregate
    end
  end

  describe 'models' do
    it "determines the underlying model for an association path" do
      path = Joiner::Path.new User, [:articles, :comments]

      expect(path.model).to eq(Comment)
    end

    it "returns the base model if the path is empty" do
      path = Joiner::Path.new User, []

      expect(path.model).to eq(User)
    end

    it "raises an exception if the path is invalid" do
      path = Joiner::Path.new User, [:articles, :likes]

      expect { path.model }.to raise_error(Joiner::AssociationNotFound)
    end
  end
end