Low commit activity in last 3 years
A long-lived project that still receives updates
RSpec scaffold generator templates that use FactoryGirl and WiceGrid
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.3.9
~> 2.0
~> 4.1
~> 3.1
~> 0.0
 Project Readme

rspec_rails_scaffold_templates¶ ↑

RSpec scaffold generator templates that

  • uses FactoryGirl to simplify form valid parameters

  • if gem WiceGrid is used prepares all the staff for index spec

  • makes all necessary stubs to use with cancan (cancancan) gem

Installation¶ ↑

Add to your Gemfile

gem 'rspec_rails_scaffold_templates'

Then bundle as usual.

Usage¶ ↑

Next time you run

rails generate scaffold SomeModel ...

you will get the needed specs for controller and views.

Configuring¶ ↑

In order to have in the generated specs the code that works around the code that checks ability you have to add to the application.rb file the config for generators as follows

config.generators do |g|
  g.cancan true
end

For the specs on views it will be

before(:each) do
  allow(controller).to receive(:can?).and_return(true)
end

while in the controller and request spec it will be

before :each do
  allow(controller).to receive(:current_user).and_return(current_user)
end

So, you need to add a method current_user to your rspec support, say, like this

def current_user(stubs = {})
  @mock_current_user ||= mock_model(User, name: 'Mock Current User').tap do |user|
    stubs.reverse_merge! is?: true, landing: nil
    stubs.each do |k, v|
      allow(user).to receive(k) {v}
    end
  end
end

You may want to stub current_ability instead of current_user in controller. For doing this replace true with :current_ability in g.cancan config like this

config.generators do |g|
  g.cancan :current_ability
end

Of course, you will need method current_ability in you spec support in this case, say, like this

class GodAbility
  include CanCan::Ability

  def initialize
    can :manage, :all
  end
end

def current_ability
  GodAbility.new
end

Contributing to rspec_rails_scaffold_templates¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2014 Dmitri Koulikoff. See LICENSE.txt for further details.