Sha256: 27b9d2c21f56b2b2536d7d94bcb2eb1240be0bfbc00f22771268f71fc9487d0a

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

<% if File.exist?(File.join %w[spec rails_helper.rb]) -%>
require 'rails_helper'
<% else -%>
require 'spec_helper'
<% end -%>

<% module_namespacing do -%>
describe <%= class_name %>, type: :model do

<% if options[:fixture_replacement] == :factory_girl -%>
  subject { create :<%= singular_name %> }
<% else -%>
  before :each do
    @valid_attrs = {
    }
  end

  subject { <%= class_name %>.create @valid_attrs }
<% end -%>

  describe 'validatins' do
    it { should be_valid }
  end   # validatins

<% if attribute = attributes.detect{|a| a.name == 'position'} || attributes.detect{|a| a.name == 'name'} || attributes.detect{|a| a.name == 'title'} || attributes.first -%>
  describe 'class methods' do
    describe 'scopes' do
      describe '.ordered' do
        it 'orders the records of <%= class_name %> by :<%=attribute.name %>' do
<% if options[:fixture_replacement] == :factory_girl -%>
          create :<%= singular_name %>
          create :<%= singular_name %>
<% else -%>
          <%= class_name %>.create @valid_attrs
          <%= class_name %>.create @valid_attrs
<% end -%>
          expect(<%= class_name %>.ordered).to eq <%= class_name %>.order(:<%=attribute.name %>)
        end
      end   # .ordered
    end   # scopes
  end   # class methods

<% end -%>
end
<% end -%>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record_model_and_rspec_enhanced_templates-1.1.0 lib/templates/rspec/model/model_spec.rb
active_record_model_and_rspec_enhanced_templates-1.0.10 lib/templates/rspec/model/model_spec.rb