File: organization_spec.rb

package info (click to toggle)
ruby-vagrant-cloud 3.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 408 kB
  • sloc: ruby: 4,343; makefile: 7
file content (87 lines) | stat: -rw-r--r-- 2,293 bytes parent folder | download | duplicates (2)
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
82
83
84
85
86
87
require "spec_helper"
require "vagrant_cloud"

describe VagrantCloud::Organization do
  let(:account) { double("account") }
  let(:username) { "USERNAME" }

  let(:subject) { described_class.new(account: account, username: username) }

  describe "#initialize" do
    it "should error if account is not provided" do
      expect { described_class.new(username: username) }.to raise_error(ArgumentError)
    end

    it "should error if username is not provided" do
      expect { described_class.new(account: account) }.to raise_error(ArgumentError)
    end
  end

  describe "#add_box" do
    it "should create a new box" do
      expect(subject.add_box("test")).to be_a(VagrantCloud::Box)
    end

    it "should add box to the collection" do
      expect(subject.boxes).to be_empty
      subject.add_box("test")
      expect(subject.boxes).not_to be_empty
    end

    it "should error if box name already exists" do
      subject.add_box("test")
      expect { subject.add_box("test") }.
        to raise_error(VagrantCloud::Error::BoxError::BoxExistsError)
    end
  end

  describe "#dirty?" do
    it "should return false by default" do
      expect(subject.dirty?).to be_falsey
    end

    it "should check dirtiness based on attribute" do
      expect(subject.dirty?(:username)).to be_falsey
    end

    context "deep check" do
      it "should return false by default" do
        expect(subject.dirty?(deep: true)).to be_falsey
      end

      context "with box collection of one clean box" do
        before do
          b = subject.add_box("test")
          b.clean(data: {created_at: Time.now.to_s})
          subject.clean!
        end

        it "should return false" do
          expect(subject.dirty?(deep: true)).to be_falsey
        end

        context "with a dirty box in collection" do
          before { subject.add_box("test2") }

          it "should return true" do
            expect(subject.dirty?(deep: true)).to be_truthy
          end
        end
      end
    end
  end

  describe "#save" do
    it "should return self" do
      expect(subject.save).to eq(subject)
    end

    context "with boxes" do
      it "should save boxes" do
        b = subject.add_box("test")
        expect(b).to receive(:save)
        subject.save
      end
    end
  end
end