You can use stub like this.

user.stub(:name).and_return("example")

But you can not use stub method to non-initialize object which is initialize in application logic (e.g. ApplicationController) In this case you need to use any_instance_of method.

ApplicationController.any_instance_of.stub(:auth?).and_return(true)

You can generate pager object using kaminari from array object.

# select admin user and push to array
user_array = User.select_admin_user

@pager = Kaminari.paginate_array(user_array).page(params[:page]).per(20)

then you can use like this.

<%= paginate @pager %>

You can check a method is called or not by using receive in rspec.

describe "#method" do
  it "should call method_b" do
    @user = Persion.new
    expect(@user).to receive(:method_b)
    
    @user.method # method_b is called in method
  end
end
  • You should call receive before method_b is called
  • You can specify call count
expect(@user).to receive(:method_b).once
expect(@user).to receive(:method_b).twice

If you want to add extra data in draper you can use :context option.

person.rb

class Persion < Draper::Decorator
  is_admin?
    context[:role] == 'admin'
  end
end

then you can pass option for each person object.

person_a = Person.decorate(people[0], context: {role: 'admin'})
  person_b = Person.decorate(people[1], context: {role: 'normal'})

  puts person_a.is_admin? # return true
  puts person_b.is_admin? # return false

Basic Usage

If you want to get params using angularjs

app.js

angular.module('app', [])
 .config(appConfig);

appConfig.$inject = ['$routeProvider'];

function appConfig($routeProvider){
  $routeProvider.when('/item', {
    templateUrl: 'xxxxx.html',
    controller : 'ItemController'
  });
}

itemController.js

angular.module('app')
  .controller('ItemController', ItemController);

ItemController.$inject = ['$routeParams'];

function ItemController($routeParams){
  // you can get params
  // url : http://example.com?page=1
  var page = $routeParams.page; // page = 1
}

Usage for No SAP page

If you do not need to create SAP page you can get params like this.

app.js

angular.module('app', [])

appConfig.$inject = ['$locationProvider'];

function appConfig($locationProvider){
  $locationProvider.html5Mode({enable: true, requireBase: false, rewriteLinks: false});
}

itemController.js

angular.module('app')
  .controller('ItemController', ItemController);

ItemController.$inject = ['$routeParams'];

function ItemController($routeParams){
  // you can get params
  // url : http://example.com?page=1
  var page = $routeParams.page; // page = 1
}