File: application_configuration_helpers.rb

package info (click to toggle)
ruby-shoulda-matchers 7.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: ruby: 34,046; sh: 280; makefile: 9
file content (49 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module UnitTests
  module ApplicationConfigurationHelpers
    def with_belongs_to_as_required_by_default(&block)
      configuring_application(
        ::ActiveRecord::Base,
        :belongs_to_required_by_default,
        true,
        &block
      )
    end

    def with_belongs_to_as_optional_by_default(&block)
      configuring_application(
        ::ActiveRecord::Base,
        :belongs_to_required_by_default,
        false,
        &block
      )
    end

    def with_strict_loading_by_default_enabled(&block)
      configuring_application(
        ::ActiveRecord::Base,
        :strict_loading_by_default,
        true,
        &block
      )
    end

    def with_strict_loading_by_default_disabled(&block)
      configuring_application(
        ::ActiveRecord::Base,
        :strict_loading_by_default,
        false,
        &block
      )
    end

    private

    def configuring_application(config, name, value)
      previous_value = config.send(name)
      config.send("#{name}=", value)
      yield
    ensure
      config.send("#{name}=", previous_value)
    end
  end
end