column_hider 0.0.2 → 0.0.3
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 +4 -4
- data/lib/column_hider/version.rb +1 -1
- data/lib/column_hider.rb +5 -5
- data/test/column_hider_test.rb +39 -1
- data/test/dummy/log/test.log +1441 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92694d59e054b7bf2a60bb47e269747e1d963fc3
|
4
|
+
data.tar.gz: 95ac8dcf140fb78bc66bac925793032f8e956c25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edaf3c141bf8d6963eabaf3dd30f928aac951951ecaa4d68f44bcdaf3f3bdda091c46986f7721e95a4cca7610f627624f66c3cc313374753790386cbb92c3121
|
7
|
+
data.tar.gz: 83d38ab53752217368371305e19f25e462a9480706b2b7a4c790d8f1a569a67f62ad72198d0136ca135762e851f437565e7e5e502c0de474939e05811804a265
|
data/lib/column_hider/version.rb
CHANGED
data/lib/column_hider.rb
CHANGED
@@ -5,20 +5,20 @@ module ColumnHider
|
|
5
5
|
# Overrides the Rails ActiveRecord Attributes "columns" method.
|
6
6
|
# This allows the logical removal of a column prior to its physical removal.
|
7
7
|
# To use, add two lines to your model:
|
8
|
-
# ` extend ColumnHider`
|
8
|
+
# ` extend ColumnHider::ActiveRecordAttributes`
|
9
9
|
# ` column_hider_columns :column_one, :column_two, ...`
|
10
10
|
#
|
11
11
|
module ActiveRecordAttributes
|
12
12
|
def column_hider_columns(*cols)
|
13
|
-
@column_hider_columns =
|
13
|
+
@column_hider_columns = {}
|
14
14
|
cols.each do |col|
|
15
|
-
@column_hider_columns
|
15
|
+
@column_hider_columns[col] = true
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def columns
|
20
|
-
@column_hider_columns ||=
|
21
|
-
super.reject { |col| @column_hider_columns.
|
20
|
+
@column_hider_columns ||= {} # just in case the model has "extend ColumnHider::ActiveRecordAttributes", but doesn't call column_hider_columns
|
21
|
+
super.reject { |col| @column_hider_columns.has_key?(col.name.to_sym) }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/test/column_hider_test.rb
CHANGED
@@ -10,7 +10,7 @@ describe ColumnHider do
|
|
10
10
|
before do
|
11
11
|
class Country < ActiveRecord::Base
|
12
12
|
establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
13
|
-
connection.create_table(:countries
|
13
|
+
connection.create_table(:countries) do |t|
|
14
14
|
t.string :name
|
15
15
|
t.string :capital
|
16
16
|
t.string :comment
|
@@ -27,6 +27,7 @@ describe ColumnHider do
|
|
27
27
|
describe '#column is removed in the model' do
|
28
28
|
let(:mock_col_arr) { %w(id name comment) }
|
29
29
|
col_arr = []
|
30
|
+
|
30
31
|
it '#shows the column is not there' do
|
31
32
|
Country.columns.each do |col|
|
32
33
|
col_arr << col.name
|
@@ -35,11 +36,18 @@ describe ColumnHider do
|
|
35
36
|
expect(col_arr).must_include('comment')
|
36
37
|
expect(col_arr).wont_include('capital')
|
37
38
|
end
|
39
|
+
|
40
|
+
it '#raises an error if we reference a hidden column' do
|
41
|
+
assert_raises ActiveRecord::UnknownAttributeError do
|
42
|
+
c = Country.new(name: 'USA', capital: 'Washington, DC', comment: 'America')
|
43
|
+
end
|
44
|
+
end
|
38
45
|
end
|
39
46
|
|
40
47
|
describe '#column is removed dynamically' do
|
41
48
|
let(:mock_col_arr) { %w(id name capital) }
|
42
49
|
col_arr = []
|
50
|
+
|
43
51
|
it '#shows the column is not there' do
|
44
52
|
Country.send :column_hider_columns, :comment
|
45
53
|
Country.columns.each do |col|
|
@@ -50,4 +58,34 @@ describe ColumnHider do
|
|
50
58
|
expect(col_arr).wont_include('comment')
|
51
59
|
end
|
52
60
|
end
|
61
|
+
|
62
|
+
describe '#multiple columns are removed dynamically' do
|
63
|
+
let(:mock_col_arr) { %w(id name) }
|
64
|
+
col_arr = []
|
65
|
+
|
66
|
+
it '#shows the column is not there' do
|
67
|
+
Country.send :column_hider_columns, :comment, :capital
|
68
|
+
Country.columns.each do |col|
|
69
|
+
col_arr << col.name
|
70
|
+
end
|
71
|
+
expect(col_arr).must_equal(mock_col_arr)
|
72
|
+
expect(col_arr).wont_include('capital')
|
73
|
+
expect(col_arr).wont_include('comment')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#no columns are removed' do
|
78
|
+
let(:mock_col_arr) { %w(id name capital comment) }
|
79
|
+
col_arr = []
|
80
|
+
|
81
|
+
it '#shows the column is not there' do
|
82
|
+
Country.send :column_hider_columns
|
83
|
+
Country.columns.each do |col|
|
84
|
+
col_arr << col.name
|
85
|
+
end
|
86
|
+
expect(col_arr).must_equal(mock_col_arr)
|
87
|
+
expect(col_arr).must_include('capital')
|
88
|
+
expect(col_arr).must_include('comment')
|
89
|
+
end
|
90
|
+
end
|
53
91
|
end
|