Sha256: 1793d8e125524789e5d35dd2d23962485bebde7cf95b88e10f57782914ec16ee

Contents?: true

Size: 1.49 KB

Versions: 19

Compression:

Stored size: 1.49 KB

Contents

require 'test_helper'

describe Merit::Rule do
  before do
    @rule = Merit::Rule.new
  end

  describe '#applies (with block)' do
    before do
      @rule.block = ->(obj) { obj.length < 4 }
    end

    it 'truthy block should make rule apply' do
      _(@rule.applies?('str')).must_be :==, true
    end

    it 'falsy block should make rule fail' do
      _(@rule.applies?('string')).must_be :==, false
    end

    it 'block needs parameter for rule to pass' do
      _(@rule.applies?).must_be :==, false
    end
  end

  describe '#applies (without block)' do
    it 'empty condition should make rule apply' do
      _(@rule.applies?).must_be :==, true
    end
  end

  describe '#badge' do
    it 'raises exception on inexistent badge' do
      @rule.badge_name = 'inexistent'
      _(-> { @rule.badge }).must_raise Merit::BadgeNotFound
    end

    it 'finds related badge by name, when the name is a string' do
      Merit::Badge.create(id: 98, name: 'test-badge-98')
      @rule.badge_name = "test-badge-98"
      _(@rule.badge).must_be :==, Merit::Badge.find(98)
    end

    it 'finds related badge by name, when the name is a symbol' do
      Merit::Badge.create(id: 100, name: :testbadge)
      @rule.badge_name = 'testbadge'
      _(@rule.badge).must_be :==, Merit::Badge.find(100)
      @rule.badge
    end

    it 'finds related badge by name' do
      Merit::Badge.create(id: 98, name: 'test-badge-98')
      @rule.badge_id = 98
      _(@rule.badge).must_be :==, Merit::Badge.find(98)
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
merit-4.0.3 test/unit/rule_unit_test.rb
qalam_merit-4.5.12 test/unit/rule_unit_test.rb
merit-4.0.2 test/unit/rule_unit_test.rb
qalam_merit-4.5.11 test/unit/rule_unit_test.rb
qalam_merit-4.5.10 test/unit/rule_unit_test.rb
qalam_merit-4.5.09 test/unit/rule_unit_test.rb
qalam_merit-4.5.08 test/unit/rule_unit_test.rb
qalam_merit-4.5.07 test/unit/rule_unit_test.rb
qalam_merit-4.5.06 test/unit/rule_unit_test.rb
qalam_merit-4.5.05 test/unit/rule_unit_test.rb
qalam_merit-4.5.04 test/unit/rule_unit_test.rb
qalam_merit-4.5.03 test/unit/rule_unit_test.rb
qalam_merit-4.5.02 test/unit/rule_unit_test.rb
qalam_merit-4.5.01 test/unit/rule_unit_test.rb
qalam_merit-4.5.00 test/unit/rule_unit_test.rb
qalam_merit-4.0.4 test/unit/rule_unit_test.rb
qalam_merit-4.0.35 test/unit/rule_unit_test.rb
merit-4.0.1 test/unit/rule_unit_test.rb
merit-4.0.0 test/unit/rule_unit_test.rb