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.11 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.10 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-rails-0.2.3 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.9 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.8 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.7 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.6 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.5 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-rails-0.2.2 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.4 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.3 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-rails-0.2.1 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.2 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.1 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-rails-0.2.0 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.2.0 deprecated_generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.1.1 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.1.0 lib/generators/graphiti/templates/resource_writes_spec.rb.erb