Module: RSpec::ActiveRecord::StubModels
- Included in:
- RSpec::ActiveRecord
- Defined in:
- lib/rspec/active_record/stub_models.rb
Overview
Used for stubbing classes in your tests
Instance Method Summary collapse
-
#create_temporary_table(*args, **options, &block) ⇒ Object
Creates temporary table.
-
#stub_class(name, parent = Object) { ... } ⇒ Object
Stub a class with specific name for testing.
-
#stub_model(name, parent = ApplicationRecord) { ... } ⇒ Object
Stub a model with specific name for testing.
Instance Method Details
#create_temporary_table(*args, **options, &block) ⇒ Object
Creates temporary table. Only works correctly if DDL transactions are enabled.
Takes same arguments as create_table in ActiveRecord migration.
42 43 44 |
# File 'lib/rspec/active_record/stub_models.rb', line 42 def create_temporary_table(*args, **, &block) ::ActiveRecord::Base.connection.create_table(*args, **, &block) end |
#stub_class(name, parent = Object) { ... } ⇒ Object
Stub a class with specific name for testing.
16 17 18 |
# File 'lib/rspec/active_record/stub_models.rb', line 16 def stub_class(name, parent = Object, &block) stub_const(name.to_s, Class.new(parent, &block)) end |
#stub_model(name, parent = ApplicationRecord) { ... } ⇒ Object
Stub a model with specific name for testing.
33 34 35 36 37 38 |
# File 'lib/rspec/active_record/stub_models.rb', line 33 def stub_model(name, parent = ApplicationRecord, &block) stub_class(name, parent) do self.table_name = name.to_s.tableize class_eval(&block) if block end end |