Module: IronTrail::Testing
- Defined in:
- lib/iron_trail/testing/rspec.rb
Defined Under Namespace
Modules: InstanceMethods
Class Attribute Summary collapse
-
.enabled ⇒ Object
Returns the value of attribute enabled.
Class Method Summary collapse
Class Attribute Details
.enabled ⇒ Object
Returns the value of attribute enabled.
27 28 29 |
# File 'lib/iron_trail/testing/rspec.rb', line 27 def enabled @enabled end |
Class Method Details
.disable! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/iron_trail/testing/rspec.rb', line 34 def disable! # We "disable" it by replacing the trigger function by a no-op one. # This should be faster than adding/removing triggers from several # tables every time. sql = <<~SQL CREATE OR REPLACE FUNCTION irontrail_log_row() RETURNS TRIGGER AS $$ BEGIN RETURN NULL; END; $$ LANGUAGE plpgsql; SQL ActiveRecord::Base.connection.execute(sql) @enabled = false end |
.enable! ⇒ Object
29 30 31 32 |
# File 'lib/iron_trail/testing/rspec.rb', line 29 def enable! DbFunctions.new(ActiveRecord::Base.connection).install_functions @enabled = true end |
.with_iron_trail(want_enabled:, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/iron_trail/testing/rspec.rb', line 51 def with_iron_trail(want_enabled:, &block) was_enabled = IronTrail::Testing.enabled if want_enabled ::IronTrail::Testing.enable! unless was_enabled else ::IronTrail::Testing.disable! if was_enabled end block.call ensure if want_enabled && !was_enabled ::IronTrail::Testing.disable! elsif !want_enabled && was_enabled ::IronTrail::Testing.enable! end end |