File: attributes_attribute_spec.rb

package info (click to toggle)
ruby-virtus 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: ruby: 4,378; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 718 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
require 'spec_helper'

describe "Adding attribute called 'attributes'" do

  context "when mass assignment is disabled" do
    before do
      module Examples
        class User
          include Virtus.model(mass_assignment: false)

          attribute :attributes
        end
      end
    end

    it "allows model to use `attributes` attribute" do
      user = Examples::User.new
      expect(user.attributes).to eq(nil)
      user.attributes = "attributes string"
      expect(user.attributes).to eq("attributes string")
    end

    it "doesn't accept `attributes` key in initializer" do
      user = Examples::User.new(attributes: 'attributes string')
      expect(user.attributes).to eq(nil)
    end
  end
end