crypt_keeper_with_ransack 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 528d5ca39a3f6a75ae4f1e5f756ffcc34650bb9d
4
- data.tar.gz: b33e77466bb883c700ac35f0b4acaa20624e5af4
3
+ metadata.gz: 70530402b5010ed3ff8b58585a68802e3eb55c36
4
+ data.tar.gz: cf3f4314fca5474ecf53e1c99fc7372269524167
5
5
  SHA512:
6
- metadata.gz: 20d2cbf5723bf06a1b4a51380b034217e651cc730d3963de5d9119739c74d3ce1c1219b63e7ca46552c8a622fec23b2afbd52bdb7276cbd4afb76b733d44d558
7
- data.tar.gz: 7746478334349b70ee47162736366155f8e6c8d2529f68839837c933a4ba4b8f3cbe366cf7c4fcc0217148841032181f97449f8272862fa30178f2e62ec1de71
6
+ metadata.gz: b4c791165388fdb48f322e4b8199195912e9b420c2cb00d096ed22996c1f7384d8d78a6555cb9ee20887f3634722317fb0b42eb6d9fe1542e2edf7e3a1558f83
7
+ data.tar.gz: b96e1af60127d4c2cac12bf45cb79f195074427e5fd63d04601f09edcdbe44fc59cf36968647af563ed0137843e95dd05a065b2e8c6cda63323f815a3f573ebe
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ /log/
@@ -19,8 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "crypt_keeper", "~> 0.18.4"
22
- spec.add_dependency "ransack", "~> 1.6.0"
22
+ spec.add_dependency "ransack", "~> 1.6"
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rails", "~> 4.1.9"
26
+ spec.add_development_dependency "pg", "~> 0.18.1"
27
+ spec.add_development_dependency "rspec-rails", "~> 3.1.0"
28
+ spec.add_development_dependency "database_cleaner", "~> 1.4.0"
26
29
  end
@@ -1,3 +1,3 @@
1
1
  module CryptKeeperWithRansack
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,5 +1,36 @@
1
1
  require "crypt_keeper_with_ransack/version"
2
+ require "crypt_keeper"
3
+ require "ransack"
2
4
 
3
5
  module CryptKeeperWithRansack
4
- # Your code goes here...
6
+ module CryptKeeper
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ alias_method_chain :crypt_keeper, :ransack
11
+ end
12
+
13
+ def crypt_keeper_with_ransack(*args)
14
+ crypt_keeper_without_ransack(*args)
15
+
16
+ crypt_keeper_fields.each do |field|
17
+ add_crypt_ransacker field, key: crypt_keeper_options[:key]
18
+ end
19
+ end
20
+ end
21
+
22
+ module Ransack
23
+ extend ActiveSupport::Concern
24
+
25
+ module ClassMethods
26
+ def add_crypt_ransacker(field, key: nil)
27
+ ransacker field do |parent|
28
+ Arel.sql "pgp_sym_decrypt(cast(#{field} AS bytea), '#{key}')"
29
+ end
30
+ end
31
+ end
32
+ end
5
33
  end
34
+
35
+ CryptKeeper::Model::ClassMethods.include CryptKeeperWithRansack::CryptKeeper
36
+ ActiveRecord::Base.include CryptKeeperWithRansack::Ransack
@@ -5,7 +5,18 @@ describe CryptKeeperWithRansack do
5
5
  expect(CryptKeeperWithRansack::VERSION).not_to be nil
6
6
  end
7
7
 
8
- it 'does something useful' do
9
- expect(false).to eq(true)
8
+ describe "#search" do
9
+ before :each do
10
+ User.create(name: 'MyText')
11
+ end
12
+
13
+ it { expect(User.find_by(name: 'MyText')).to be_nil }
14
+ it { expect(User.search_by_plaintext(:name, 'MyText').count).to eq 1 }
15
+
16
+ it { expect(User.where(name: 'MyText').count).to eq 0 }
17
+ it { expect(User.search(name_eq: 'MyText').result.count).to eq 1 }
18
+
19
+ it { expect(User.search(name_cont: 'My').result.count).to eq 1 }
20
+ it { expect(User.search(name_cont: 'Your').result.count).to eq 0 }
10
21
  end
11
22
  end
data/spec/fake_app.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'active_record'
2
+ require 'pg'
3
+
4
+ PG_SPEC = {
5
+ :adapter => 'postgresql',
6
+ :database => 'crypt_keeper_with_ransack_test',
7
+ :encoding => 'utf8'
8
+ }
9
+
10
+ # config
11
+ ActiveRecord::Base.establish_connection(PG_SPEC.merge(database: 'postgres', schema_search_path: 'public'))
12
+ ActiveRecord::Base.connection.drop_database PG_SPEC[:database] rescue nil
13
+ ActiveRecord::Base.connection.create_database(PG_SPEC[:database])
14
+ ActiveRecord::Base.establish_connection(PG_SPEC)
15
+
16
+ module CryptKeeperWithRansackTestApp
17
+ class Application < Rails::Application
18
+ config.secret_token = [*'A'..'z'].join
19
+ config.session_store :cookie_store, :key => '_myapp_session'
20
+ config.active_support.deprecation = :log
21
+ config.eager_load = false
22
+ end
23
+ end
24
+ CryptKeeperWithRansackTestApp::Application.initialize!
25
+
26
+ # models
27
+ class User < ActiveRecord::Base
28
+ crypt_keeper :name, encryptor: :postgres_pgp, key: 'super_good_password', ransacker: true
29
+ end
30
+
31
+ # migrations
32
+ class CreateAllTables < ActiveRecord::Migration
33
+ def self.up
34
+ enable_extension :pgcrypto
35
+ create_table(:users) do |t|
36
+ t.text :name
37
+ t.timestamps
38
+ end
39
+ end
40
+
41
+ def self.down
42
+ drop_table :users
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,28 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rails'
3
+ require 'active_record'
2
4
  require 'crypt_keeper_with_ransack'
5
+ require 'fake_app'
6
+ require 'rspec/rails'
7
+ require 'database_cleaner'
8
+
9
+ RSpec.configure do |config|
10
+ config.before :all do
11
+ CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
12
+ end
13
+
14
+ config.before :suite do
15
+ DatabaseCleaner.strategy = :transaction
16
+ DatabaseCleaner.clean_with :truncation
17
+ end
18
+
19
+ config.around :each do |example|
20
+ DatabaseCleaner.cleaning do
21
+ example.run
22
+ end
23
+ end
24
+
25
+ config.after :each do
26
+ DatabaseCleaner.clean
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypt_keeper_with_ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maimai77
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crypt_keeper
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.0
33
+ version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.0
40
+ version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +67,61 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.1.9
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.1.9
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: 0.18.1
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.18.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: database_cleaner
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.4.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
81
123
  - !ruby/object:Gem::Version
82
- version: '0'
124
+ version: 1.4.0
83
125
  description: ''
84
126
  email:
85
127
  - kohta0707@gmail.com
@@ -98,6 +140,7 @@ files:
98
140
  - lib/crypt_keeper_with_ransack.rb
99
141
  - lib/crypt_keeper_with_ransack/version.rb
100
142
  - spec/crypt_keeper_with_ransack_spec.rb
143
+ - spec/fake_app.rb
101
144
  - spec/spec_helper.rb
102
145
  homepage: ''
103
146
  licenses:
@@ -125,4 +168,5 @@ specification_version: 4
125
168
  summary: add ransacker for crypted attributes
126
169
  test_files:
127
170
  - spec/crypt_keeper_with_ransack_spec.rb
171
+ - spec/fake_app.rb
128
172
  - spec/spec_helper.rb