Sha256: f132b76d734d3859f93cf5cb515286dd942fac9df8611fe665e139a078675c1a

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require_relative '../spec_helper'

require "cancan/matchers"

describe Ability, "for :<%= name %>" do

  before do
    @<%= name %> = Factory.create(:<%= name %>_user)
  end
  
  subject { Ability.new(@<%= name -%>) }
  
<% if ability_definitions.empty? -%>
# Define your ability tests thus;
#
#  describe 'on Activity' do
#
#    before do
#      @activity = Factory.create(:activity)
#    end
#
#    it { should be_able_to( :index,    Activity  ) }
#    it { should be_able_to( :show,     @activity ) }
#    it { should be_able_to( :read,     @activity ) }
#    it { should be_able_to( :new,      @activity ) }
#    it { should be_able_to( :create,   @activity ) }
#    it { should be_able_to( :edit,     @activity ) }
#    it { should be_able_to( :update,   @activity ) }
#    it { should be_able_to( :destroy,  @activity ) }
#
#  end
#  # on Activity
<% else -%>
<% definitions do |model, definition| -%>
  
  describe 'on <%= model.camelize -%>' do

    before do
      @<%= model -%> = Factory.create(:<%= model -%>)
    end
    
<% definition.cans.each do |can| -%>
    it { should be_able_to( <%= ":#{can},".ljust(12, ' ') + (can == 'index' ? model.camelize : "@#{model}") -%> ) }
<% end -%>
<%- definition.cannots.each do |cannot| -%>
    it { should_not be_able_to( <%= ":#{cannot},".ljust(12, ' ') + (cannot == 'index' ? model.camelize : "@#{model}") -%> ) }
<% end -%>

  end
  # on <%= model.camelize %>
  <% end -%>
  
<% end -%>  
end
  

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
canard-0.2.3 lib/generators/rspec/ability/templates/abilities_spec.rb.erb
canard-0.2.2 lib/generators/rspec/ability/templates/abilities_spec.rb.erb
canard-0.2.1 lib/generators/rspec/ability/templates/abilities_spec.rb.erb
canard-0.2.0 lib/generators/rspec/ability/templates/abilities_spec.rb.erb
canard-0.1.2 lib/generators/rspec/ability/templates/abilities_spec.rb.erb
canard-0.1.1 lib/generators/rspec/ability/templates/abilities_spec.rb.erb
canard-0.1.0 lib/generators/rspec/ability/templates/abilities_spec.rb.erb