rails-flog 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d92f9e5659c4ddc5b1cff2a221c211024678286
4
- data.tar.gz: 3f436f911028bb5e1ec6edf651f77c4d4edc6b94
3
+ metadata.gz: aa2793786fbf497001272ed0f4efd872d07bd6bf
4
+ data.tar.gz: a0be8008a8f86e3cfa1c98159642cac72dff9827
5
5
  SHA512:
6
- metadata.gz: dc59c520f5e43959612424651280796903b23f48277e68c7373272d5602c4fcd846efe499b0cc01a7cb92df1313017d1db7b19ec6184e68132bb6bb9fb03e46c
7
- data.tar.gz: c4701cef3be35296f50ab97cfd01d782b886b8e7291f667e153fc7a7184f4457ac813695ca9bc73d92d433a250445d49a828aeb6c1217dfebf8173ef1bdbf6e6
6
+ metadata.gz: 55ea880d7174a20e8aabf0bfd2af712432e2734cef2174c8eb07c7978006ac55af533ddbd3c5811ec82ee588c20f2e1fb8c93b45c9545b050e87b3e9c153a789
7
+ data.tar.gz: 43093dfa7504fc0da76745e5e8e0e5b8c5ee29a106e2c897e619872cfd93ef62fea0ef5bf128badda3a7c9983a3cea7dafef2643607b9421bf4307bfe4f3c6a2
data/.travis.yml CHANGED
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ # - 2.1.0
5
6
  gemfile:
6
7
  - gemfiles/rails_3_2_x.gemfile
7
8
  - gemfiles/rails_4_0_x.gemfile
9
+ # - gemfiles/rails_4_1_x.gemfile
data/README.md CHANGED
@@ -89,7 +89,13 @@ Just install.
89
89
 
90
90
  ## Disable temporary
91
91
 
92
- If you put a file named `no-flog.txt` to `<rails_app>/tmp` direcotry, `rails-flog` will disable format.
92
+ If you put a file to `<rails_app>/tmp` direcotry, `rails-flog` will disable format.
93
+
94
+ |File name |Feature |
95
+ |:------------------|:----------|
96
+ |no-flog-sql.txt |SQL |
97
+ |no-flog-params.txt |Parameters |
98
+ |no-flog.txt |Both |
93
99
 
94
100
  ## Supported versions
95
101
 
@@ -109,3 +115,4 @@ If you put a file named `no-flog.txt` to `<rails_app>/tmp` direcotry, `rails-flo
109
115
  - v1.0.0 (2013-11-28 JST): First release
110
116
  - v1.1.0 (2013-12-02 JST): Add feature that disables format by no-flog.txt
111
117
  - v1.1.1 (2013-12-06 JST): Change to alias_method_change from alias for method aliasing
118
+ - v1.2.0 (2014-01-14 JST): Add feature that disables format partially by no-flog-sql.txt and no-flog-params.txt
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~>4.1.0"
4
+ gem "anbt-sql-formatter"
5
+ gem "awesome_print"
6
+
7
+ gemspec :path => "../"
8
+
@@ -8,7 +8,7 @@ class ActionController::LogSubscriber
8
8
  include Flog::PayloadValueShuntable
9
9
 
10
10
  def start_processing_with_flog(event)
11
- return start_processing_without_flog(event) unless Flog::Status.enabled?
11
+ return start_processing_without_flog(event) unless Flog::Status.params_formattable?
12
12
 
13
13
  replaced = replace_params(event.payload[:params])
14
14
 
@@ -6,7 +6,7 @@ class ActiveRecord::LogSubscriber
6
6
  include Flog::PayloadValueShuntable
7
7
 
8
8
  def sql_with_flog(event)
9
- return sql_without_flog(event) unless Flog::Status.enabled?
9
+ return sql_without_flog(event) unless Flog::Status.sql_formattable?
10
10
 
11
11
  formatted = format_sql(event.payload[:sql])
12
12
 
data/lib/flog/status.rb CHANGED
@@ -4,11 +4,30 @@ require "rails"
4
4
  module Flog
5
5
  class Status
6
6
  SWITCH_FILE_NAME = "no-flog.txt"
7
+ SQL_SWITCH_FILE_NAME = "no-flog-sql.txt"
8
+ PARAMS_SWITCH_FILE_NAME = "no-flog-params.txt"
7
9
 
8
10
  def self.enabled?
9
- !File.exist?(Rails.root.join("tmp", SWITCH_FILE_NAME).to_s)
11
+ !switch_file_exists?(SWITCH_FILE_NAME)
10
12
  rescue
11
13
  true
12
14
  end
15
+
16
+ def self.sql_formattable?
17
+ enabled? && !switch_file_exists?(SQL_SWITCH_FILE_NAME)
18
+ rescue
19
+ true
20
+ end
21
+
22
+ def self.params_formattable?
23
+ enabled? && !switch_file_exists?(PARAMS_SWITCH_FILE_NAME)
24
+ rescue
25
+ true
26
+ end
27
+
28
+ private
29
+ def self.switch_file_exists?(file_name)
30
+ File.exist?(Rails.root.join("tmp", file_name).to_s)
31
+ end
13
32
  end
14
33
  end
data/lib/flog/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # coding: utf-8
2
2
  module Flog
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
@@ -69,6 +69,14 @@ class ParamsFormattableTest < ActionController::TestCase
69
69
  end
70
70
  end
71
71
 
72
+ def test_parameters_log_is_not_formatted_when_params_formattable_is_false
73
+ Flog::Status.expects(:params_formattable?).returns(false)
74
+ get :show, foo: "foo_value", bar: "bar_value"
75
+ assert_logger do |logger|
76
+ assert logger.infos[1].include?(%(Parameters: {"foo"=>"foo_value", "bar"=>"bar_value"}))
77
+ end
78
+ end
79
+
72
80
  private
73
81
  def assert_logger(&block)
74
82
  if ActionController::Base.logger.errors.present?
@@ -60,6 +60,14 @@ class SqlFormattableTest < ActiveSupport::TestCase
60
60
  end
61
61
  end
62
62
 
63
+ def test_sql_is_not_formatted_when_sql_formattable_is_false
64
+ Flog::Status.expects(:sql_formattable?).returns(false)
65
+ Book.where(category: "comics").to_a
66
+ assert_logger do |logger|
67
+ assert logger.debugs.first.include?(%(SELECT "books".* FROM "books" WHERE "books"."category" = 'comics'))
68
+ end
69
+ end
70
+
63
71
  private
64
72
  def assert_logger(&block)
65
73
  if ActiveRecord::Base.logger.errors.present?
@@ -4,11 +4,12 @@ require "rails"
4
4
  class StatusTest < ActiveSupport::TestCase
5
5
  def setup
6
6
  @test_root = Pathname.new(File.expand_path(File.dirname(__FILE__) + "../../"))
7
- @switch_file_path = @test_root.join("tmp", Flog::Status::SWITCH_FILE_NAME)
8
7
  end
9
8
 
10
9
  def teardown
11
10
  delete_switch_file
11
+ delete_sql_switch_file
12
+ delete_params_switch_file
12
13
  end
13
14
 
14
15
  def test_enabled_is_true_when_switch_file_does_not_exist
@@ -17,7 +18,7 @@ class StatusTest < ActiveSupport::TestCase
17
18
  end
18
19
 
19
20
  def test_enabled_is_false_when_switch_file_exists
20
- Rails.expects(:root).returns(@test_root)
21
+ Rails.expects(:root).at_most(2).returns(@test_root)
21
22
  create_switch_file
22
23
  assert_equal false, Flog::Status.enabled?
23
24
  end
@@ -28,14 +29,106 @@ class StatusTest < ActiveSupport::TestCase
28
29
  assert Flog::Status.enabled?
29
30
  end
30
31
 
32
+ def test_sql_formattable_is_true_when_enable_and_sql_switch_file_does_not_exist
33
+ Rails.expects(:root).at_most(2).returns(@test_root)
34
+ delete_switch_file
35
+ delete_sql_switch_file
36
+ assert Flog::Status.sql_formattable?
37
+ end
38
+
39
+ def test_sql_formattable_is_false_when_enable_and_sql_switch_file_exists
40
+ Rails.expects(:root).at_most(2).returns(@test_root)
41
+ delete_switch_file
42
+ create_sql_switch_file
43
+ assert_equal false, Flog::Status.sql_formattable?
44
+ end
45
+
46
+ def test_sql_formattable_is_false_when_disable_and_sql_switch_file_not_exist
47
+ Rails.expects(:root).at_most(2).returns(@test_root)
48
+ create_switch_file
49
+ delete_sql_switch_file
50
+ assert_equal false, Flog::Status.sql_formattable?
51
+ end
52
+
53
+ def test_sql_formattable_is_true_when_error_is_raised_in_process
54
+ Rails.expects(:root).at_most(2).returns(nil) # For raise NoMethodError
55
+ create_sql_switch_file
56
+ assert Flog::Status.sql_formattable?
57
+ end
58
+
59
+ def test_sql_formattable_is_false_when_disable_and_sql_switch_file_exists
60
+ Rails.expects(:root).at_most(2).returns(@test_root)
61
+ create_switch_file
62
+ create_sql_switch_file
63
+ assert_equal false, Flog::Status.sql_formattable?
64
+ end
65
+
66
+ def test_params_formattable_is_true_when_enable_and_params_switch_file_does_not_exist
67
+ Rails.expects(:root).at_most(2).returns(@test_root)
68
+ delete_switch_file
69
+ delete_params_switch_file
70
+ assert Flog::Status.params_formattable?
71
+ end
72
+
73
+ def test_params_formattable_is_false_when_enable_and_params_switch_file_exists
74
+ Rails.expects(:root).at_most(2).returns(@test_root)
75
+ delete_switch_file
76
+ create_params_switch_file
77
+ assert_equal false, Flog::Status.params_formattable?
78
+ end
79
+
80
+ def test_params_formattable_is_false_when_disable_and_params_switch_file_not_exist
81
+ Rails.expects(:root).at_most(2).returns(@test_root)
82
+ create_switch_file
83
+ delete_params_switch_file
84
+ assert_equal false, Flog::Status.params_formattable?
85
+ end
86
+
87
+ def test_params_formattable_is_false_when_disable_and_params_switch_file_exists
88
+ Rails.expects(:root).at_most(2).returns(@test_root)
89
+ create_switch_file
90
+ create_params_switch_file
91
+ assert_equal false, Flog::Status.params_formattable?
92
+ end
93
+
94
+ def test_params_formattable_is_true_when_error_is_raised_in_process
95
+ Rails.expects(:root).at_most(2).returns(nil) # For raise NoMethodError
96
+ create_params_switch_file
97
+ assert Flog::Status.params_formattable?
98
+ end
99
+
31
100
  private
32
101
  def create_switch_file
33
- File.open(@switch_file_path, "w").close
102
+ create_file(@test_root.join("tmp", Flog::Status::SWITCH_FILE_NAME))
34
103
  end
35
104
 
36
105
  def delete_switch_file
37
- if File.exist?(@switch_file_path)
38
- File.delete(@switch_file_path)
106
+ delete_file(@test_root.join("tmp", Flog::Status::SWITCH_FILE_NAME))
107
+ end
108
+
109
+ def create_sql_switch_file
110
+ create_file(@test_root.join("tmp", Flog::Status::SQL_SWITCH_FILE_NAME))
111
+ end
112
+
113
+ def delete_sql_switch_file
114
+ delete_file(@test_root.join("tmp", Flog::Status::SQL_SWITCH_FILE_NAME))
115
+ end
116
+
117
+ def create_params_switch_file
118
+ create_file(@test_root.join("tmp", Flog::Status::PARAMS_SWITCH_FILE_NAME))
119
+ end
120
+
121
+ def delete_params_switch_file
122
+ delete_file(@test_root.join("tmp", Flog::Status::PARAMS_SWITCH_FILE_NAME))
123
+ end
124
+
125
+ def create_file(file_path)
126
+ File.open(file_path, "w").close
127
+ end
128
+
129
+ def delete_file(file_path)
130
+ if File.exist?(file_path)
131
+ File.delete(file_path)
39
132
  end
40
133
  end
41
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-flog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pinzolo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,6 +138,7 @@ files:
138
138
  - Rakefile
139
139
  - gemfiles/rails_3_2_x.gemfile
140
140
  - gemfiles/rails_4_0_x.gemfile
141
+ - gemfiles/rails_4_1_x.gemfile
141
142
  - lib/flog.rb
142
143
  - lib/flog/params_formattable.rb
143
144
  - lib/flog/payload_value_shuntable.rb