Sha256: 0e015970061c7d541d8be1603834ef82232472c5de792682c26cd78008ef0311

Contents?: true

Size: 1.81 KB

Versions: 21

Compression:

Stored size: 1.81 KB

Contents

shared_examples_for "an ActiveModel" do
  subject { described_class.new }

  describe '#to_key' do
    it 'should respond' do
      expect(subject).to respond_to :to_key
    end

    it 'should return nil when #persisted? is false ' do
      def subject.persisted?() false end
      expect(subject.to_key).to eq nil
    end
  end

  describe '#to_param' do
    it 'should respond' do
      expect(subject).to respond_to :to_param
    end

    it 'should return nil when #persisted? is false ' do
      def subject.persisted?() false end
      expect(subject.to_param).to eq nil
    end
  end

  describe '#model_name' do
    let(:model_name) { subject.class.model_name }

    it 'should have a model name' do
      expect(model_name).to respond_to :to_str
    end

    it 'should have a human name' do
      expect(model_name.human).to respond_to :to_str
    end

    it 'should have a singular name' do
      expect(model_name.singular).to respond_to :to_str
    end

    it 'should have a plural name' do
      expect(model_name.plural).to respond_to :to_str
    end
  end

  describe '#to_partial_path' do
    it 'should return a string' do
      expect(subject.to_partial_path).to be_a String
    end
  end

  describe '#persisted?' do
    it 'should return a boolean' do
      expect(match_boolean(subject.persisted?)).to be true
    end
  end

  describe '#valid?' do
    it 'should return a boolean' do
      expect(match_boolean(subject.valid?)).to be true
    end
  end

  describe '#new_record' do
    it 'should return a boolean' do
      expect(match_boolean(subject.new_record?)).to be true
    end
  end

  describe '#destroyed?' do
    it 'should return a boolean' do
      expect(match_boolean(subject.destroyed?)).to be true
    end
  end

  private 
  
    def match_boolean(result)
      result == true || result == false
    end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
active-triples-0.4.1 spec/support/active_model_lint.rb
active-triples-0.7.6 spec/support/active_model_lint.rb
active-triples-0.7.5 spec/support/active_model_lint.rb
active-triples-0.7.4 spec/support/active_model_lint.rb
active-triples-0.7.3 spec/support/active_model_lint.rb
active-triples-0.7.2 spec/support/active_model_lint.rb
active-triples-0.7.1 spec/support/active_model_lint.rb
active-triples-0.7.0 spec/support/active_model_lint.rb
active-triples-0.6.1 spec/support/active_model_lint.rb
active-triples-0.6.0 spec/support/active_model_lint.rb
active-triples-0.5.0 spec/support/active_model_lint.rb
active_triples-local_name-0.1.0 spec/support/active_model_lint.rb
active-triples-0.4.0 spec/support/active_model_lint.rb
active-triples-0.3.1 spec/support/active_model_lint.rb
active-triples-0.3.0 spec/support/active_model_lint.rb
active-triples-0.2.3 spec/support/active_model_lint.rb
active-triples-0.2.2 spec/support/active_model_lint.rb
active-triples-0.2.1 spec/support/active_model_lint.rb
active-triples-0.2.0 spec/support/active_model_lint.rb
active-triples-0.1.2 spec/support/active_model_lint.rb