Class: ActiveMocker::LoadedMocks
- Inherits:
-
Object
- Object
- ActiveMocker::LoadedMocks
- Defined in:
- lib/active_mocker/loaded_mocks.rb
Class Method Summary collapse
-
.all ⇒ Object
Returns Hash key being a string of the active_record class name and the value being the mocked class.
-
.class_name_to_mock ⇒ Object
Returns Hash {“ActiveRecordModel” => MockVersion}, key being a string of the active_record class name and the value being the mocked class.
-
.clear_all ⇒ Object
Calls clear_all for all mocks, which deletes all saved records and removes mock_class/instance_method.
-
.delete_all ⇒ Object
Calls delete_all for all mocks, which deletes all saved records.
-
.find(klass) ⇒ Object
Input ActiveRecord Model as String returns ActiveMock equivalent class.
Class Method Details
.all ⇒ Object
Returns Hash key being a string of the active_record class name and the value being the mocked class.
ActiveMocker::LoadedMocks.all
=> {'PersonMock' => PersonMock}
17 18 19 |
# File 'lib/active_mocker/loaded_mocks.rb', line 17 def all mocks end |
.class_name_to_mock ⇒ Object
Returns Hash {“ActiveRecordModel” => MockVersion}, key being a string of the active_record class name and the value being the mocked class. Any sub classed mocked will override the original mock until clear_all is called.
ActiveMocker::LoadedMocks.class_name_to_mock
=> {'Person' => PersonMock}
40 41 42 43 44 |
# File 'lib/active_mocker/loaded_mocks.rb', line 40 def class_name_to_mock mocks.values.each_with_object({}) do |mock_constant, hash| hash[mock_constant.send(:mocked_class)] = mock_constant end.merge(subclasses) end |
.clear_all ⇒ Object
Calls clear_all for all mocks, which deletes all saved records and removes mock_class/instance_method.
It will also clear any sub classed mocks from the list
Method will be deprecated in v2 because mocking is deprecated
24 25 26 27 |
# File 'lib/active_mocker/loaded_mocks.rb', line 24 def clear_all all_mocks.each { |m| m.clear_mock } clear_subclasses end |
.delete_all ⇒ Object
Calls delete_all for all mocks, which deletes all saved records.
31 32 33 |
# File 'lib/active_mocker/loaded_mocks.rb', line 31 def delete_all all_mocks.each { |m| m.delete_all } end |
.find(klass) ⇒ Object
Input ActiveRecord Model as String returns ActiveMock equivalent class.
+find('User')+ => UserMock
9 10 11 |
# File 'lib/active_mocker/loaded_mocks.rb', line 9 def find(klass) class_name_to_mock[klass] end |