Skip to content

Instantly share code, notes, and snippets.

@jaredbeck
Created April 15, 2019 19:58
Show Gist options
  • Select an option

  • Save jaredbeck/83607c9c98222f0496356ac04e51f981 to your computer and use it in GitHub Desktop.

Select an option

Save jaredbeck/83607c9c98222f0496356ac04e51f981 to your computer and use it in GitHub Desktop.

Revisions

  1. jaredbeck created this gist Apr 15, 2019.
    64 changes: 64 additions & 0 deletions symbol_to_proc_test.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    # frozen_string_literal: true

    require "bundler/inline"

    gemfile(true) do
    source "https://rubygems.org"
    gem "cancancan", "3.0.0"
    gem "rails", "5.2.3"
    gem "sqlite3"
    end

    require 'active_record'
    require 'cancancan'
    require 'cancan/model_adapters/active_record_adapter'
    require 'cancan/model_adapters/active_record_4_adapter'
    require 'minitest/autorun'
    require 'logger'

    # This connection will do for database-independent bug reports.
    ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
    ActiveRecord::Base.logger = Logger.new(STDOUT)

    ActiveRecord::Schema.define do
    create_table :tasks, force: true do |t|
    t.datetime :deleted_on
    end
    end

    class Task < ActiveRecord::Base
    # wrong number of arguments (given 1, expected 0)
    def deleted?
    deleted_on.present?
    end
    end

    class Ability
    include CanCan::Ability

    def initialize(user)
    can :edit, Task
    cannot :edit, Task, &:deleted?

    # Workaround: change the above to this form
    #
    # cannot :edit, Task do |t|
    # t.deleted?
    # end
    end
    end

    class BugTest < Minitest::Test
    def test_association_stuff
    task = Task.create!
    ability = Ability.new(nil)
    assert ability.can?(:edit, task)
    # Error:
    # BugTest#test_association_stuff:
    # ArgumentError: wrong number of arguments (given 1, expected 0)
    #
    # Exception `ArgumentError' at
    # .../cancancan-3.0.0/lib/cancan/conditions_matcher.rb:24 -
    # wrong number of arguments (given 1, expected 0)
    end
    end