Sha256: 1f5931a688af09239a38a407ae257aba42eef677eeb1c33783d3775698383252

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

require 'rails_helper'

RSpec.describe <%= resource_class %>, type: :resource do
  describe 'serialization' do
    let!(:<%= var %>) { create(:<%= var %>) }

    it 'works' do
      render
      data = jsonapi_data[0]
      expect(data.id).to eq(<%= var %>.id)
      expect(data.jsonapi_type).to eq('<%= type %>')
      <%- attributes.each do |a| -%>
      <%- if [:created_at, :updated_at].include?(a.name.to_sym) -%>
      expect(data.<%= a.name %>).to eq(datetime(<%= file_name %>.<%= a.name %>))
      <%- else -%>
      expect(data.<%= a.name %>).to eq(<%= file_name %>.<%= a.name %>)
      <%- end -%>
      <%- end -%>
    end
  end
  <%- if actions?('index') -%>

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

    context 'by id' do
      before do
        params[:filter] = { id: { eq: <%= var %>2.id } }
      end

      it 'works' do
        render
        expect(d.map(&:id)).to eq([<%= var %>2.id])
      end
    end
  end

  describe 'sorting' do
    context 'by id descending' do
      let!(:<%= var %>1) { create(:<%= var %>) }
      let!(:<%= var %>2) { create(:<%= var %>) }

      before do
        params[:sort] = '-id'
      end

      it 'works' do
        render
        expect(d.map(&:id)).to eq([
          <%= var %>2.id,
          <%= var %>1.id
        ])
      end
    end
  end
  <%- end -%>

  describe 'sideloading' do
    # ... your tests ...
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
graphiti-1.0.alpha.17 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.16 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.15 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.14 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.12 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.11 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.10 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.9 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.8 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.7 lib/generators/graphiti/templates/resource_reads_spec.rb.erb
graphiti-1.0.alpha.6 lib/generators/graphiti/templates/resource_reads_spec.rb.erb