Sha256: 1bd76cc1d2670c59369b97d3b41c6325df7d4888715b9f6fbbb7341e2861bcfc

Contents?: true

Size: 1.49 KB

Versions: 78

Compression:

Stored size: 1.49 KB

Contents

require 'rails_helper'

RSpec.describe <%= resource_class %>, type: :resource do
  describe 'creating' do
    let(:payload) do
      {
        data: {
          type: '<%= type %>',
      <%- if defined?(FactoryBot) -%>
          attributes: attributes_for(:<%= type.to_s.singularize %>)
       <%- else -%>
          attributes: { }
       <%- end -%>
        }
      }
    end

    let(:instance) do
      <%= resource_class %>.build(payload)
    end

    it 'works' do
      expect {
        expect(instance.save).to eq(true), instance.errors.full_messages.to_sentence
      }.to change { <%= model_class %>.count }.by(1)
    end
  end

  describe 'updating' do
    let!(:<%= var %>) { create(:<%= var %>) }

    let(:payload) do
      {
        data: {
          id: <%= var %>.id.to_s,
          type: '<%= type %>',
          attributes: { } # Todo!
        }
      }
    end

    let(:instance) do
      <%= resource_class %>.find(payload)
    end

    xit 'works (add some attributes and enable this spec)' do
      expect {
        expect(instance.update_attributes).to eq(true)
      }.to change { <%= var %>.reload.updated_at }
      # .and change { <%= var %>.foo }.to('bar') <- example
    end
  end

  describe 'destroying' do
    let!(:<%= var %>) { create(:<%= var %>) }

    let(:instance) do
      <%= resource_class %>.find(id: <%= var %>.id)
    end

    it 'works' do
      expect {
        expect(instance.destroy).to eq(true)
      }.to change { <%= model_class %>.count }.by(-1)
    end
  end
end

Version data entries

78 entries across 78 versions & 2 rubygems

Version Path
graphiti-1.2.33 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.32 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.31 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.30 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.29 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.28 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.27 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.26 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.25 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-rails-0.2.4 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.21 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.20 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.19 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.18 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.17 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.16 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.15 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.14 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.13 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.12 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb