Sha256: 6e020439791376fae6f79d771fa464709bc379d40f6dd1de3018ae8a0860cce4

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 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 %>).
            except("created_at", "updated_at")
       <%- 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

16 entries across 16 versions & 1 rubygems

Version Path
graphiti-1.0.3 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.2 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.1 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.0 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.28 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.27 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.26 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.25 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.24 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.23 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.22 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.21 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.19 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.18 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.17 lib/generators/graphiti/templates/resource_writes_spec.rb.erb
graphiti-1.0.rc.16 lib/generators/graphiti/templates/resource_writes_spec.rb.erb