Sha256: 6faba67f93b8b619f6ad06f1bb59a629d95d8f627cb9dfb18424125c4fbbcaf9
Contents?: true
Size: 1.52 KB
Versions: 7
Compression:
Stored size: 1.52 KB
Contents
require_relative "../spec_helper" class ExportedLimitsTest < Lanes::TestCase module FakeScope extend ActiveSupport::Concern class_methods do def scope(*args) # act like ActiveRecord model end end end class Base include FakeScope include Lanes::Concerns::ExportScope include Lanes::Concerns::ExportMethods end class LimitsTestingModel < Base def secret_method( name, query ) end def test_method( name, query ) end export_methods :test_method, limit: lambda{ | user, type, name | user == 'anon' } scope :admin_data, lambda { | param | param }, export: {limit: :only_admins} export_methods :secret_method, limit: :only_admins def self.only_admins( user, type, name ) return user == 'admin' end end def test_limits assert LimitsTestingModel.has_exported_method?( 'test_method', 'anon' ), "anyone can retrieve no_limit data" assert LimitsTestingModel.has_exported_scope?( 'admin_data', 'admin' ), "Admins can retrieve admin data" refute LimitsTestingModel.has_exported_scope?( 'admin_data', 'non-admin' ), "Non-Admin cannot retrieve admin data" assert LimitsTestingModel.has_exported_method?( 'secret_method', 'admin' ), "Public can retrieve public data" refute LimitsTestingModel.has_exported_method?( 'secret_method', 'unk' ), "User must be admin to retrieve public data" end end
Version data entries
7 entries across 7 versions & 1 rubygems