egov_utils 0.4.15 → 0.4.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -9
- data/app/resources/egov_utils/love.rb +54 -0
- data/app/resources/egov_utils/organization.rb +21 -0
- data/lib/egov_utils/engine.rb +7 -1
- data/lib/egov_utils/settings.rb +6 -0
- data/lib/egov_utils/version.rb +1 -1
- data/lib/tasks/egov_utils_tasks.rake +38 -3
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 468a3e3707028c65d702784c7954712c1e89e73c23bf84b61109d9caf73513bd
|
4
|
+
data.tar.gz: 9aed28508bf75995324770966307ac293e630de58a46ee22c10572ea6a457d38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b5077fa2c120314964b8b62057762741d3839b64f84533896a21d348f81a03c76dc2837a4a860eb607c3b42805fb861a4addbfdaf2168f7d44d6e7818bf57bd
|
7
|
+
data.tar.gz: ce5e980887007a9286bd9b7dd690e79870f25c0120400a9fa456e47be01730d077afbe58bdcc9d6291c8d0637d203147d6e5cf691164acf855bd47c2399e599d
|
data/Rakefile
CHANGED
@@ -4,15 +4,15 @@ rescue LoadError
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
5
|
end
|
6
6
|
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
7
|
+
#require 'rdoc/task'
|
8
|
+
|
9
|
+
# RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
# rdoc.rdoc_dir = 'rdoc'
|
11
|
+
# rdoc.title = 'EgovUtils'
|
12
|
+
# rdoc.options << '--line-numbers'
|
13
|
+
# rdoc.rdoc_files.include('README.md')
|
14
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
# end
|
16
16
|
|
17
17
|
APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
|
18
18
|
load 'rails/tasks/engine.rake'
|
@@ -17,6 +17,32 @@ end
|
|
17
17
|
|
18
18
|
|
19
19
|
module EgovUtils
|
20
|
+
class LoveMock < OpenStruct
|
21
|
+
def self.all
|
22
|
+
raise NotImplemented # you need to provide .all for your mock class
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.where(clauses = {})
|
26
|
+
all.select do |l|
|
27
|
+
clauses.all? do |(k, filter)|
|
28
|
+
case filter
|
29
|
+
when Array
|
30
|
+
filter = filter.collect(&:to_s)
|
31
|
+
value = l.send(k)
|
32
|
+
pp k, filter, value
|
33
|
+
if value.is_a?(Array)
|
34
|
+
!(value.collect(&:to_s) & filter).empty?
|
35
|
+
else
|
36
|
+
filter.include?(value.to_s)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
l.send(k) == filter
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
20
46
|
class Love < ::ActiveResource::Base
|
21
47
|
|
22
48
|
def self.config
|
@@ -32,5 +58,33 @@ module EgovUtils
|
|
32
58
|
raise ArgumentError, "expected a clauses Hash, got #{clauses.inspect}" unless clauses.is_a? Hash
|
33
59
|
find(:all, params: {f: clauses})
|
34
60
|
end
|
61
|
+
|
62
|
+
|
63
|
+
# mocking
|
64
|
+
|
65
|
+
def self.inherited(subclass)
|
66
|
+
mock_subclass(subclass) if @mocking
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.mocked_classes
|
70
|
+
@mocked_classes ||= {}
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.mock!
|
74
|
+
@mocking = true
|
75
|
+
EgovUtils::Love.subclasses.each do |cls|
|
76
|
+
mock_subclass(cls)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.mock_subclass(subclass)
|
81
|
+
mock_cls = "#{subclass.name}Mock".safe_constantize
|
82
|
+
return unless mock_cls
|
83
|
+
mocked_classes[subclass.name] = subclass
|
84
|
+
namespaces = subclass.name.split('::')
|
85
|
+
namespace = (namespaces[0..-2].join('::').presence || 'Object').safe_constantize
|
86
|
+
namespace.send(:remove_const, namespaces[-1])
|
87
|
+
namespace.const_set(namespaces[-1], mock_cls)
|
88
|
+
end
|
35
89
|
end
|
36
90
|
end
|
@@ -1,4 +1,25 @@
|
|
1
1
|
module EgovUtils
|
2
|
+
class OrganizationMock < LoveMock
|
3
|
+
def self.all(*attrs)
|
4
|
+
[
|
5
|
+
new(id: 1, name: 'Městský soud 1', key: '104000', category_abbrev: 'MS' ),
|
6
|
+
new(id: 2, name: 'Krajský soud 1', key: '204000', category_abbrev: 'KS' ),
|
7
|
+
new(id: 3, name: 'Krajský soud 2', key: '205000', category_abbrev: 'KS' ),
|
8
|
+
new(id: 13, name: 'Okresní soud 1', key: '204001', category_abbrev: 'OS' )
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by_key(key)
|
13
|
+
all.detect{ |o| o.key == key }
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.region_courts(branches=false)
|
17
|
+
all.select{ |o| %w{KS MS}.include?(o.category_abbrev) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def branch_of_id; end
|
21
|
+
end
|
22
|
+
|
2
23
|
class Organization < Love
|
3
24
|
|
4
25
|
def self.find_by_key(key)
|
data/lib/egov_utils/engine.rb
CHANGED
@@ -25,7 +25,7 @@ module EgovUtils
|
|
25
25
|
|
26
26
|
config.generators do |g|
|
27
27
|
g.test_framework :rspec
|
28
|
-
g.fixture_replacement :
|
28
|
+
g.fixture_replacement :factory_bot, :dir => 'spec/factories'
|
29
29
|
end
|
30
30
|
|
31
31
|
initializer :append_migrations do |app|
|
@@ -131,5 +131,11 @@ module EgovUtils
|
|
131
131
|
FactoryBot.definition_file_paths << EgovUtils::Engine.root.join('spec', 'factories')
|
132
132
|
end
|
133
133
|
end
|
134
|
+
|
135
|
+
initializer 'egov_utils.mock_resources' do
|
136
|
+
if EgovUtils::Settings.mock_resources?
|
137
|
+
EgovUtils::Love.mock!
|
138
|
+
end
|
139
|
+
end
|
134
140
|
end
|
135
141
|
end
|
data/lib/egov_utils/settings.rb
CHANGED
@@ -23,6 +23,10 @@ module EgovUtils
|
|
23
23
|
allow_internal_accounts? && allow_password_reset
|
24
24
|
end
|
25
25
|
|
26
|
+
def mock_resources?
|
27
|
+
mock_resources
|
28
|
+
end
|
29
|
+
|
26
30
|
end
|
27
31
|
|
28
32
|
Settings['allow_register'] ||= false
|
@@ -31,4 +35,6 @@ module EgovUtils
|
|
31
35
|
Settings['redmine'] ||= Settingslogic.new({})
|
32
36
|
Settings['redmine']['enabled'] ||= false
|
33
37
|
|
38
|
+
Settings['mock_resources'] ||= !Rails.env.production?
|
39
|
+
|
34
40
|
end
|
data/lib/egov_utils/version.rb
CHANGED
@@ -1,4 +1,39 @@
|
|
1
1
|
# desc "Explaining what the task does"
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
namespace :egov_utils do
|
3
|
+
|
4
|
+
task create_admin: :environment do
|
5
|
+
pwd = SecureRandom.hex(8)
|
6
|
+
u = EgovUtils::User.new(login: 'admin', mail: 'admin@admin.cz', password: pwd, password_confirmation: pwd, active: true, roles: ['admin'])
|
7
|
+
if u.save
|
8
|
+
puts "User 'admin' created with password '#{pwd}'"
|
9
|
+
else
|
10
|
+
u.errors.full_messages.each{ |m| puts m }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
task :require_factory_bot do
|
15
|
+
require 'factory_bot'
|
16
|
+
end
|
17
|
+
|
18
|
+
task cleanup_db: :environment do
|
19
|
+
require 'database_cleaner'
|
20
|
+
|
21
|
+
raise "This is very dangerous method and is not meant to be run in production" if Rails.env.production?
|
22
|
+
|
23
|
+
admins = EgovUtils::User.where(login: 'admin').collect do |u|
|
24
|
+
u.attributes.except('id', 'created_at', 'updated_at')
|
25
|
+
.merge('password' => 'abcdefgh', 'password_confirmation' => 'abcdefgh')
|
26
|
+
end
|
27
|
+
users = EgovUtils::User.where.not(provider: nil).collect{|u| u.attributes.except('id', 'created_at', 'updated_at') }
|
28
|
+
DatabaseCleaner.clean_with :truncation
|
29
|
+
EgovUtils::User.create(users)
|
30
|
+
EgovUtils::User.create(admins).each do |admin|
|
31
|
+
attrs = admins.detect{ |a| a['login'] == admin.login }
|
32
|
+
admin.update_columns(password_digest: attrs['password_digest'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
task load_staging_data: [:require_factory_bot, :cleanup_db] do
|
37
|
+
require Rails.root.join('db', 'staging.rb')
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: egov_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Ezr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5.
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bcrypt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '5.
|
47
|
+
version: '5.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '5.
|
54
|
+
version: '5.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: haml
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -689,8 +689,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
689
689
|
- !ruby/object:Gem::Version
|
690
690
|
version: '0'
|
691
691
|
requirements: []
|
692
|
-
|
693
|
-
rubygems_version: 2.7.7
|
692
|
+
rubygems_version: 3.0.3
|
694
693
|
signing_key:
|
695
694
|
specification_version: 4
|
696
695
|
summary: The eGoverment utilities is set of functionalities to support basic eGoverment
|