File: base_spec.rb

package info (click to toggle)
ruby-orm-adapter 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 180 kB
  • ctags: 88
  • sloc: ruby: 698; makefile: 4
file content (81 lines) | stat: -rw-r--r-- 2,984 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'spec_helper'

describe OrmAdapter::Base do
  subject { OrmAdapter::Base.new(Object) }

  describe "#extract_conditions!" do
    let(:conditions) { {:foo => 'bar'} }
    let(:order) { [[:foo, :asc]] }
    let(:limit) { 1 }
    let(:offset) { 2 }

    it "(<conditions>)" do
      subject.send(:extract_conditions!, conditions).should == [conditions, [], nil, nil]
    end

    it "(:conditions => <conditions>)" do
      subject.send(:extract_conditions!, :conditions => conditions).should == [conditions, [], nil, nil]
    end

    it "(:order => <order>)" do
      subject.send(:extract_conditions!, :order => order).should == [{}, order, nil, nil]
    end

    it "(:limit => <limit>)" do
      subject.send(:extract_conditions!, :limit => limit).should == [{}, [], limit, nil]
    end

    it "(:offset => <offset>)" do
      subject.send(:extract_conditions!, :offset => offset).should == [{}, [], nil, offset]
    end

    it "(:conditions => <conditions>, :order => <order>)" do
      subject.send(:extract_conditions!, :conditions => conditions, :order => order).should == [conditions, order, nil, nil]
    end

    it "(:conditions => <conditions>, :limit => <limit>)" do
      subject.send(:extract_conditions!, :conditions => conditions, :limit => limit).should == [conditions, [], limit, nil]
    end

    it "(:conditions => <conditions>, :offset => <offset>)" do
      subject.send(:extract_conditions!, :conditions => conditions, :offset => offset).should == [conditions, [], nil, offset]
    end

    describe "#valid_object?" do
      it "determines whether an object is valid for the current model class" do
        subject.send(:valid_object?, Object.new).should be_true
        subject.send(:valid_object?, String.new).should be_false
      end
    end

    describe "#normalize_order" do
      specify "(nil) returns []" do
        subject.send(:normalize_order, nil).should == []
      end

      specify ":foo returns [[:foo, :asc]]" do
        subject.send(:normalize_order, :foo).should == [[:foo, :asc]]
      end

      specify "[:foo] returns [[:foo, :asc]]" do
        subject.send(:normalize_order, [:foo]).should == [[:foo, :asc]]
      end

      specify "[:foo, :desc] returns [[:foo, :desc]]" do
        subject.send(:normalize_order, [:foo, :desc]).should == [[:foo, :desc]]
      end

      specify "[:foo, [:bar, :asc], [:baz, :desc], :bing] returns [[:foo, :asc], [:bar, :asc], [:baz, :desc], [:bing, :asc]]" do
        subject.send(:normalize_order, [:foo, [:bar, :asc], [:baz, :desc], :bing]).should == [[:foo, :asc], [:bar, :asc], [:baz, :desc], [:bing, :asc]]
      end

      specify "[[:foo, :wtf]] raises ArgumentError" do
        lambda { subject.send(:normalize_order, [[:foo, :wtf]]) }.should raise_error(ArgumentError)
      end

      specify "[[:foo, :asc, :desc]] raises ArgumentError" do
        lambda { subject.send(:normalize_order, [[:foo, :asc, :desc]]) }.should raise_error(ArgumentError)
      end
    end
  end
end