aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/model_attribute_spec.rb
blob: ad1dd863fae53fd636c2334d39d8d5f7ba97e75d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
RSpec.describe ModelAttribute do
  describe ".define" do
    it "adds a new instance of ModelAttribute to @@all" do
      expect do
        ModelAttribute.define(:route, :name, :string)
      end.to change { ModelAttribute.all.length }.by(1)

      model_attr = ModelAttribute.all.last

      expect(model_attr).to be_an_instance_of(ModelAttribute)
      expect(model_attr.klass).to eq(:route)
      expect(model_attr.name).to eq(:name)
      expect(model_attr.data_type).to eq(:string)
    end
  end

  describe "#code" do
    it "returns a string representation of the attribute" do
      model_attr = ModelAttribute.new(:route, :name, :string)

      expect(model_attr.code).to eq('route#name')
    end
  end
end