Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

feature request: add generator for resource spec file #11

Open
Fivell opened this issue Jun 12, 2017 · 2 comments
Open

feature request: add generator for resource spec file #11

Fivell opened this issue Jun 12, 2017 · 2 comments

Comments

@Fivell
Copy link

Fivell commented Jun 12, 2017

Hello, generator for resource spec file can be helpful

@ramontayag
Copy link
Contributor

@Fivell I don't have a lot of experience with generators. If you do, feel free to add it :)

@BatuhanW
Copy link

We should start from somewhere, so I'm dropping this to here.

require 'rails_helper'

RSpec.describe Resource, type: :resource do
  # let(:user) { create(:user) }
  let(:data) { create() }

  # Some attributes, creatable, updatable fields might be user related
  # subject { described_class.new(data, { current_user: user }) }
  subject { described_class.new(data, {}) }

  it { is_expected.to have_primary_key(:id) }

  context '#attributes' do
    attributes = [:attribute]

    attributes.each do |attribute|
      it { is_expected.to have_attribute(attribute) }
    end
  end

  context '#relationships' do
    context '#one' do
      # it { is_expected.to have_one(:relationship) }
    end

    context '#many' do
      # it { is_expected.to have_many(:relationship) }
    end
  end

  context '#filter' do
    filters = [:field]

    filters.each do |filter|
      it { is_expected.to filter(filter) }
    end
  end

  context '#fields' do
    context '#sortable' do
      sortables = [:field]

      sortables.each do |sortable|
        it { is_expected.to have_sortable_field(sortable) }
      end
    end

    context '#creatable' do
      context '#valid' do
        fields = [:field]

        fields.each do |field|
          # it { is_expected.to have_creatable_field(field) }
        end
      end

      context '#invalid' do
        fields = [:field]

        fields.each do |field|
          # it { is_expected.to_not have_creatable_field(field) }
        end
      end
    end

    context '#updatable' do
      context '#valid' do
        fields = [:field]

        fields.each do |field|
          # it { is_expected.to_not have_updatable_field(field) }
        end
      end

      context '#invalid' do
        fields = [:field]

        fields.each do |field|
          # it { is_expected.to_not have_updatable_field(field) }
        end
      end
    end
  end
end

@Fivell

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants