Class: ActiveRecordFormatter::Collector
- Inherits:
-
Object
- Object
- ActiveRecordFormatter::Collector
- Defined in:
- lib/rspec/activerecord/formatter/collector.rb
Constant Summary collapse
- SKIP_QUERIES =
["SELECT tablename FROM pg_tables", "select sum(ct) from (select count(*) ct from"]
Instance Attribute Summary collapse
-
#objects_count ⇒ Object
readonly
Returns the value of attribute objects_count.
-
#query_count ⇒ Object
readonly
Returns the value of attribute query_count.
-
#total_objects ⇒ Object
readonly
Returns the value of attribute total_objects.
-
#total_queries ⇒ Object
readonly
Returns the value of attribute total_queries.
Instance Method Summary collapse
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
- #record_query(*_unused, data) ⇒ Object
- #reset_example ⇒ Object
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
8 9 10 11 12 13 14 15 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 8 def initialize @query_count = 0 @objects_count = 0 @total_queries = 0 @total_objects = 0 ActiveSupport::Notifications.subscribe("sql.active_record", method(:record_query)) end |
Instance Attribute Details
#objects_count ⇒ Object (readonly)
Returns the value of attribute objects_count.
5 6 7 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 5 def objects_count @objects_count end |
#query_count ⇒ Object (readonly)
Returns the value of attribute query_count.
5 6 7 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 5 def query_count @query_count end |
#total_objects ⇒ Object (readonly)
Returns the value of attribute total_objects.
5 6 7 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 5 def total_objects @total_objects end |
#total_queries ⇒ Object (readonly)
Returns the value of attribute total_queries.
5 6 7 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 5 def total_queries @total_queries end |
Instance Method Details
#record_query(*_unused, data) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 17 def record_query(*_unused, data) return if SKIP_QUERIES.any? { |q| data[:sql].index(q) == 0 } @query_count += 1 @total_queries += 1 if query_is_an_insert?(data[:sql]) @objects_count += 1 @total_objects += 1 end end |
#reset_example ⇒ Object
29 30 31 32 |
# File 'lib/rspec/activerecord/formatter/collector.rb', line 29 def reset_example @query_count = 0 @objects_count = 0 end |