acts_as_footprintable 0.6.1 → 0.6.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 +4 -4
- data/.rubocop.yml +32 -0
- data/Gemfile +5 -4
- data/Rakefile +4 -2
- data/acts_as_footprintable.gemspec +22 -13
- data/config.ru +3 -3
- data/gemfiles/rails_5.0.gemfile +2 -0
- data/gemfiles/rails_5.1.gemfile +2 -0
- data/gemfiles/rails_5.2.gemfile +2 -0
- data/gemfiles/rails_6.0.gemfile +2 -0
- data/gemfiles/rails_6.1.gemfile +2 -0
- data/gemfiles/rails_7.0.gemfile +2 -0
- data/lib/acts_as_footprintable/extenders/footprintable.rb +5 -4
- data/lib/acts_as_footprintable/extenders/footprinter.rb +4 -3
- data/lib/acts_as_footprintable/footprint.rb +5 -3
- data/lib/acts_as_footprintable/footprintable.rb +2 -1
- data/lib/acts_as_footprintable/footprinter.rb +29 -11
- data/lib/acts_as_footprintable/version.rb +3 -1
- data/lib/acts_as_footprintable.rb +2 -0
- data/lib/generators/acts_as_footprintable/migration/migration_generator.rb +13 -11
- data/lib/generators/acts_as_footprintable/migration/templates/active_record/migration.rb +2 -0
- data/test/footprintable_test.rb +29 -28
- data/test/footprinter_test.rb +27 -25
- data/test/internal/app/models/footprintable.rb +4 -3
- data/test/internal/app/models/not_footprintable.rb +4 -3
- data/test/internal/app/models/not_user.rb +3 -2
- data/test/internal/app/models/second_footprintable.rb +4 -3
- data/test/internal/app/models/user.rb +3 -2
- data/test/test_helper.rb +25 -21
- metadata +87 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4dda61f4d4e76bc6ee5251d8591b51f6888e7d70609cb16d21601faa07d2014
|
|
4
|
+
data.tar.gz: '0148bca9da729db5fe61d7c92da7c84ae5e0812ea15d49e73fdb328d37d4ba1e'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a96376414507b2bb3067460c0f0a359afe11afe92ebb863dd2d69d8b7dd9cc82ada52c5e2a53f3f21b871780bc4edf71d1b57257c7af7bcc1232da8e99c13bde
|
|
7
|
+
data.tar.gz: a239b306ad678c186d65284c50099d2183eded818c78723ffdaa04f05819a110d7cba5f8e838d0aa100d9efe5d5c87563db753b95f400067b6572b4fb6e9d9b1
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
- rubocop-rake
|
|
4
|
+
- rubocop-minitest
|
|
5
|
+
|
|
6
|
+
inherit_from: .rubocop_todo.yml
|
|
7
|
+
|
|
8
|
+
AllCops:
|
|
9
|
+
NewCops: enable
|
|
10
|
+
TargetRubyVersion: 2.6
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'lib/generators/acts_as_footprintable/migration/templates/active_record/migration.rb'
|
|
13
|
+
|
|
14
|
+
Layout/LineLength:
|
|
15
|
+
AllowHeredoc: true
|
|
16
|
+
AllowURI: true
|
|
17
|
+
|
|
18
|
+
Metrics/MethodLength:
|
|
19
|
+
IgnoredMethods:
|
|
20
|
+
- acts_as_footprintable
|
|
21
|
+
- recent_footprint_ids
|
|
22
|
+
|
|
23
|
+
Metrics/BlockLength:
|
|
24
|
+
IgnoredMethods:
|
|
25
|
+
- describe
|
|
26
|
+
- refine
|
|
27
|
+
|
|
28
|
+
Layout/DotPosition:
|
|
29
|
+
EnforcedStyle: trailing
|
|
30
|
+
|
|
31
|
+
Style/Documentation:
|
|
32
|
+
Enabled: false
|
data/Gemfile
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
source 'https://rubygems.org'
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
4
5
|
|
|
5
6
|
# Specify your gem's dependencies in acts_as_footprintable.gemspec
|
|
6
7
|
gemspec
|
|
7
8
|
|
|
8
|
-
gem '
|
|
9
|
-
gem 'sqlite3'
|
|
9
|
+
gem 'activerecord'
|
|
10
|
+
gem 'sqlite3'
|
data/Rakefile
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'English'
|
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
6
|
require 'acts_as_footprintable/version'
|
|
5
7
|
|
|
6
8
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
9
|
+
spec.name = 'acts_as_footprintable'
|
|
8
10
|
spec.version = ActsAsFootprintable::VERSION
|
|
9
|
-
spec.author =
|
|
10
|
-
spec.email =
|
|
11
|
-
spec.description =
|
|
12
|
-
spec.summary =
|
|
13
|
-
spec.homepage =
|
|
14
|
-
spec.license =
|
|
11
|
+
spec.author = 'Toyoaki Oko'
|
|
12
|
+
spec.email = 'chariderpato@gmail.com'
|
|
13
|
+
spec.description = 'Rails gem to allowing records to leave footprints'
|
|
14
|
+
spec.summary = 'Rails gem to allowing records to leave footprints'
|
|
15
|
+
spec.homepage = 'https://github.com/patorash/acts_as_footprintable'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
15
18
|
|
|
16
|
-
spec.files = `git ls-files`.split(
|
|
19
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
17
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
spec.require_paths = [
|
|
22
|
+
spec.require_paths = ['lib']
|
|
23
|
+
spec.required_ruby_version = '>= 2.6'
|
|
20
24
|
|
|
21
|
-
spec.
|
|
22
|
-
spec.add_development_dependency 'timecop', '~> 0'
|
|
25
|
+
spec.add_dependency 'activerecord', '< 7.1.0', '>= 5.0.0'
|
|
23
26
|
spec.add_development_dependency 'database_cleaner', '~> 2.0'
|
|
27
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 1.24'
|
|
29
|
+
spec.add_development_dependency 'rubocop-minitest', '~> 0.17'
|
|
30
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.13'
|
|
31
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.6'
|
|
32
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
|
24
33
|
end
|
data/config.ru
CHANGED
data/gemfiles/rails_5.0.gemfile
CHANGED
data/gemfiles/rails_5.1.gemfile
CHANGED
data/gemfiles/rails_5.2.gemfile
CHANGED
data/gemfiles/rails_6.0.gemfile
CHANGED
data/gemfiles/rails_6.1.gemfile
CHANGED
data/gemfiles/rails_7.0.gemfile
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module ActsAsFootprintable
|
|
3
4
|
module Extenders
|
|
4
5
|
module Footprintable
|
|
@@ -15,9 +16,9 @@ module ActsAsFootprintable
|
|
|
15
16
|
true
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def self.access_ranking(range=nil, limit=nil)
|
|
19
|
+
def self.access_ranking(range = nil, limit = nil)
|
|
19
20
|
records = Footprint.for_type(self)
|
|
20
|
-
records = records.where(:
|
|
21
|
+
records = records.where(created_at: range) unless range.nil?
|
|
21
22
|
records = records.limit(limit) unless limit.nil?
|
|
22
23
|
records.group(:footprintable_id).order('count_footprintable_id desc').count(:footprintable_id)
|
|
23
24
|
end
|
|
@@ -25,4 +26,4 @@ module ActsAsFootprintable
|
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
|
-
end
|
|
29
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module ActsAsFootprintable
|
|
3
4
|
module Extenders
|
|
4
5
|
module Footprinter
|
|
@@ -6,7 +7,7 @@ module ActsAsFootprintable
|
|
|
6
7
|
false
|
|
7
8
|
end
|
|
8
9
|
|
|
9
|
-
def acts_as_footprinter(*
|
|
10
|
+
def acts_as_footprinter(*_args)
|
|
10
11
|
require 'acts_as_footprintable/footprinter'
|
|
11
12
|
include ActsAsFootprintable::Footprinter
|
|
12
13
|
|
|
@@ -18,4 +19,4 @@ module ActsAsFootprintable
|
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
|
-
end
|
|
22
|
+
end
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActsAsFootprintable
|
|
2
4
|
class Footprint < ::ActiveRecord::Base
|
|
3
5
|
belongs_to :footprintable, polymorphic: true
|
|
4
6
|
belongs_to :footprinter, polymorphic: true
|
|
5
7
|
|
|
6
|
-
scope :for_type,
|
|
7
|
-
scope :by_type,
|
|
8
|
+
scope :for_type, ->(klass) { where(footprintable_type: klass.name) }
|
|
9
|
+
scope :by_type, ->(klass) { where(footprinter_type: klass.name) }
|
|
8
10
|
|
|
9
11
|
validates :footprintable_id, presence: true
|
|
10
12
|
validates :footprinter_id, presence: true
|
|
11
13
|
end
|
|
12
|
-
end
|
|
14
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActsAsFootprintable
|
|
2
4
|
module Footprinter
|
|
3
5
|
def self.included(base)
|
|
@@ -15,30 +17,46 @@ module ActsAsFootprintable
|
|
|
15
17
|
footprint.save
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
def access_histories_for(klass, limit=nil)
|
|
20
|
+
def access_histories_for(klass, limit = nil)
|
|
19
21
|
get_access_history_records(footprints.for_type(klass), limit)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
def access_histories(limit=nil)
|
|
24
|
+
def access_histories(limit = nil)
|
|
23
25
|
get_access_history_records(footprints, limit)
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
private
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
def get_access_history_records(target, limit = nil)
|
|
31
|
+
footprints.where(id: recent_footprint_ids(target, limit)).order('created_at DESC')
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
def table_name
|
|
32
35
|
ActsAsFootprintable::Footprint.table_name
|
|
33
36
|
end
|
|
34
37
|
|
|
35
|
-
def recent_footprint_ids(target, limit=nil)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
def recent_footprint_ids(target, limit = nil)
|
|
39
|
+
records = footprints.where(<<~SQL)
|
|
40
|
+
(
|
|
41
|
+
#{table_name}.footprintable_id,
|
|
42
|
+
#{table_name}.footprintable_type,
|
|
43
|
+
#{table_name}.created_at
|
|
44
|
+
) IN (#{recent_footprints_by(target).to_sql})
|
|
45
|
+
SQL
|
|
46
|
+
records = records.order('footprints.created_at desc')
|
|
40
47
|
records = records.limit(limit) unless limit.nil?
|
|
41
|
-
records.
|
|
48
|
+
records.ids
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def recent_footprints_by(target)
|
|
52
|
+
target.group(
|
|
53
|
+
"#{table_name}.footprintable_id",
|
|
54
|
+
"#{table_name}.footprintable_type"
|
|
55
|
+
).select(
|
|
56
|
+
"#{table_name}.footprintable_id",
|
|
57
|
+
"#{table_name}.footprintable_type",
|
|
58
|
+
"MAX(#{table_name}.created_at) AS created_at"
|
|
59
|
+
)
|
|
42
60
|
end
|
|
43
61
|
end
|
|
44
|
-
end
|
|
62
|
+
end
|
|
@@ -1,41 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails/generators/migration'
|
|
2
4
|
|
|
3
5
|
module ActsAsFootprintable
|
|
4
6
|
class MigrationGenerator < Rails::Generators::Base
|
|
5
7
|
include Rails::Generators::Migration
|
|
6
8
|
|
|
7
|
-
desc
|
|
9
|
+
desc 'Generators migration for footprintable(footprints table)'
|
|
8
10
|
|
|
9
11
|
def self.orm
|
|
10
12
|
Rails::Generators.options[:rails][:orm]
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def self.source_root
|
|
14
|
-
File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.
|
|
16
|
+
File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.instance_of?(String)))
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def self.orm_has_migration?
|
|
18
20
|
[:active_record].include? orm
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
def self.next_migration_number(
|
|
22
|
-
Time.now.utc.strftime(
|
|
23
|
+
def self.next_migration_number(_path)
|
|
24
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def create_migration_file
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
return unless self.class.orm_has_migration?
|
|
29
|
+
|
|
30
|
+
migration_template 'migration.rb',
|
|
31
|
+
'db/migrate/acts_as_footprintable_migration.rb',
|
|
32
|
+
migration_version: migration_version
|
|
29
33
|
end
|
|
30
34
|
|
|
31
35
|
def migration_version
|
|
32
|
-
if over_rails5?
|
|
33
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
|
34
|
-
end
|
|
36
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if over_rails5?
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
def over_rails5?
|
|
38
40
|
Rails::VERSION::MAJOR >= 5
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
|
-
end
|
|
43
|
+
end
|
data/test/footprintable_test.rb
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
require 'acts_as_footprintable/footprintable'
|
|
3
5
|
|
|
4
6
|
describe ActsAsFootprintable::Footprintable do
|
|
5
|
-
|
|
6
|
-
it "should not be a footprintable" do
|
|
7
|
+
it 'should not be a footprintable' do
|
|
7
8
|
expect(NotFootprintable).wont_be :footprintable?
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
it
|
|
11
|
+
it 'should be a footprintable' do
|
|
11
12
|
expect(Footprintable).must_be :footprintable?
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
describe 'leave footprints by footprinter' do
|
|
15
|
-
let(:user) { User.create!(:
|
|
16
|
-
let(:user2) { User.create!(:
|
|
17
|
-
let(:footprintable) { Footprintable.create!(:
|
|
18
|
-
let(:footprintable2) { Footprintable.create!(:
|
|
16
|
+
let(:user) { User.create!(name: 'i can footprint!') }
|
|
17
|
+
let(:user2) { User.create!(name: 'a new person') }
|
|
18
|
+
let(:footprintable) { Footprintable.create!(name: 'a footprinting model') }
|
|
19
|
+
let(:footprintable2) { Footprintable.create!(name: 'a 2nd footprinting model') }
|
|
19
20
|
|
|
20
|
-
it
|
|
21
|
+
it 'should be leave footprints' do
|
|
21
22
|
expect(footprintable.leave_footprints(user)).must_equal true
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
it
|
|
25
|
+
it '足跡の数が増えていること' do
|
|
25
26
|
expect(footprintable.footprint_count).must_equal 0
|
|
26
27
|
footprintable.leave_footprints user
|
|
27
28
|
expect(footprintable.footprint_count).must_equal 1
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
it
|
|
31
|
+
it '10回アクセスしたら10になること' do
|
|
31
32
|
expect(footprintable.footprint_count).must_equal 0
|
|
32
33
|
10.times { footprintable.leave_footprints user }
|
|
33
34
|
expect(footprintable.footprint_count).must_equal 10
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
it
|
|
37
|
+
it '複数人でアクセスしたら合計されること' do
|
|
37
38
|
expect(footprintable.footprint_count).must_equal 0
|
|
38
39
|
5.times { footprintable.leave_footprints user }
|
|
39
40
|
5.times { footprintable.leave_footprints user2 }
|
|
40
41
|
expect(footprintable.footprint_count).must_equal 10
|
|
41
42
|
end
|
|
42
43
|
|
|
43
|
-
describe
|
|
44
|
+
describe '期間指定をする' do
|
|
44
45
|
before do
|
|
45
|
-
(
|
|
46
|
-
|
|
46
|
+
1.upto(30) do |day|
|
|
47
|
+
travel_to Time.parse("2013-09-#{day}") do
|
|
47
48
|
5.times { footprintable.leave_footprints user }
|
|
48
49
|
end
|
|
49
50
|
end
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
describe
|
|
53
|
-
it
|
|
54
|
-
|
|
53
|
+
describe '1週間の場合' do
|
|
54
|
+
it '35の足跡があること' do
|
|
55
|
+
travel_to Time.parse('2013-09-30 10:00:00') do
|
|
55
56
|
expect(footprintable.footprint_count_between(1.week.ago..Time.now)).must_equal 35
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
59
|
end
|
|
59
60
|
|
|
60
|
-
describe
|
|
61
|
-
it
|
|
62
|
-
|
|
61
|
+
describe '1ヶ月の場合' do
|
|
62
|
+
it '150の足跡があること' do
|
|
63
|
+
travel_to Time.parse('2013-09-30 10:00:00') do
|
|
63
64
|
expect(footprintable.footprint_count_between(1.month.ago..Time.now)).must_equal 150
|
|
64
65
|
end
|
|
65
66
|
end
|
|
@@ -67,14 +68,14 @@ describe ActsAsFootprintable::Footprintable do
|
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
70
|
|
|
70
|
-
describe
|
|
71
|
-
let(:user) { User.create!(:
|
|
71
|
+
describe 'アクセスランキングを作成' do
|
|
72
|
+
let(:user) { User.create!(name: 'i can footprint!') }
|
|
72
73
|
|
|
73
|
-
describe
|
|
74
|
+
describe '件数と期間を制限' do
|
|
74
75
|
before do
|
|
75
|
-
(
|
|
76
|
-
|
|
77
|
-
footprintable = Footprintable.create!(:
|
|
76
|
+
1.upto(30) do |index|
|
|
77
|
+
travel_to Time.parse("2013-09-#{index}") do
|
|
78
|
+
footprintable = Footprintable.create!(name: "Footprintable#{index}")
|
|
78
79
|
index.times { footprintable.leave_footprints user }
|
|
79
80
|
end
|
|
80
81
|
end
|
|
@@ -85,7 +86,7 @@ describe ActsAsFootprintable::Footprintable do
|
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
it 'アクセスランキングが取得できること' do
|
|
88
|
-
expect(subject).must_equal
|
|
89
|
+
expect(subject).must_equal({ 7 => 7, 6 => 6, 5 => 5, 4 => 4, 3 => 3 })
|
|
89
90
|
end
|
|
90
91
|
|
|
91
92
|
it '5件取得できること' do
|
|
@@ -93,4 +94,4 @@ describe ActsAsFootprintable::Footprintable do
|
|
|
93
94
|
end
|
|
94
95
|
end
|
|
95
96
|
end
|
|
96
|
-
end
|
|
97
|
+
end
|
data/test/footprinter_test.rb
CHANGED
|
@@ -1,61 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
require 'acts_as_footprintable/footprinter'
|
|
3
5
|
|
|
4
6
|
describe ActsAsFootprintable::Footprinter do
|
|
5
|
-
|
|
6
|
-
it "should not be a footprinter" do
|
|
7
|
+
it 'should not be a footprinter' do
|
|
7
8
|
expect(NotUser).wont_be :footprinter?
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
it
|
|
11
|
+
it 'should be a footprinter' do
|
|
11
12
|
expect(User).must_be :footprinter?
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
describe
|
|
15
|
-
let(:
|
|
15
|
+
describe 'ユーザーのアクセス履歴を' do
|
|
16
|
+
let(:user1) { User.create!(name: 'user1') }
|
|
16
17
|
before do
|
|
17
|
-
(
|
|
18
|
+
1.upto(5) do |index|
|
|
18
19
|
footprintable = Footprintable.create!(name: "footprintable#{index}")
|
|
19
20
|
second_footprintable = SecondFootprintable.create!(name: "second_footprintable#{index}")
|
|
20
21
|
3.times do
|
|
21
|
-
footprintable.leave_footprints
|
|
22
|
-
second_footprintable.leave_footprints
|
|
22
|
+
footprintable.leave_footprints user1
|
|
23
|
+
second_footprintable.leave_footprints user1
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
describe
|
|
28
|
-
it
|
|
29
|
-
expect(
|
|
30
|
-
|
|
28
|
+
describe '対象のモデル毎に' do
|
|
29
|
+
it '取得できること' do
|
|
30
|
+
expect(user1.access_histories_for(Footprintable).count).must_equal 5
|
|
31
|
+
expected_data = 5.downto(1).map { |i| "footprintable#{i}" }
|
|
32
|
+
expect(user1.access_histories_for(Footprintable).map(&:footprintable).pluck(:name)).must_equal expected_data
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
it
|
|
34
|
-
expect(
|
|
35
|
-
|
|
35
|
+
it '件数を絞り込めること' do
|
|
36
|
+
expect(user1.access_histories_for(Footprintable, 3).count).must_equal 3
|
|
37
|
+
expected_data = 5.downto(3).map { |i| "footprintable#{i}" }
|
|
38
|
+
expect(user1.access_histories_for(Footprintable, 3).map(&:footprintable).pluck(:name)).must_equal expected_data
|
|
36
39
|
end
|
|
37
40
|
end
|
|
38
41
|
|
|
39
|
-
describe
|
|
40
|
-
it
|
|
41
|
-
expect(
|
|
42
|
-
footprintable_names = (1
|
|
42
|
+
describe '全てのモデルを通じて' do
|
|
43
|
+
it '取得できること' do
|
|
44
|
+
expect(user1.access_histories.count).must_equal 10
|
|
45
|
+
footprintable_names = 5.downto(1).each_with_object([]) do |index, results|
|
|
43
46
|
results.push "second_footprintable#{index}"
|
|
44
47
|
results.push "footprintable#{index}"
|
|
45
|
-
results
|
|
46
48
|
end
|
|
47
|
-
expect(
|
|
49
|
+
expect(user1.access_histories.map(&:footprintable).pluck(:name)).must_equal footprintable_names
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
it
|
|
51
|
-
expect(
|
|
52
|
+
it '件数を絞り込める事' do
|
|
53
|
+
expect(user1.access_histories(3).count).must_equal 3
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
describe 'アクセス履歴のないユーザーの場合' do
|
|
56
|
-
let(:
|
|
58
|
+
let(:user2) { User.create!(name: 'user2') }
|
|
57
59
|
it '件数が0件であること' do
|
|
58
|
-
expect(
|
|
60
|
+
expect(user2.access_histories_for(Footprintable).count).must_equal 0
|
|
59
61
|
end
|
|
60
62
|
end
|
|
61
63
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,53 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'minitest/autorun'
|
|
2
4
|
require 'active_record'
|
|
3
|
-
|
|
5
|
+
require 'active_support/testing/time_helpers'
|
|
4
6
|
require 'database_cleaner/active_record'
|
|
5
|
-
require
|
|
6
|
-
require 'timecop'
|
|
7
|
+
require 'acts_as_footprintable'
|
|
7
8
|
|
|
8
|
-
Dir["#{Dir.pwd}/test/internal/app/models/*.rb"].each
|
|
9
|
+
Dir["#{Dir.pwd}/test/internal/app/models/*.rb"].sort.each { |f| require f }
|
|
9
10
|
|
|
10
11
|
ActiveRecord::Base.establish_connection('adapter' => 'sqlite3', 'database' => ':memory:')
|
|
11
12
|
ActiveRecord::Schema.define do
|
|
12
|
-
create_table :footprints, :
|
|
13
|
-
t.references :footprintable, :
|
|
14
|
-
t.references :footprinter, :
|
|
15
|
-
t.timestamps :
|
|
13
|
+
create_table :footprints, force: true do |t|
|
|
14
|
+
t.references :footprintable, polymorphic: true
|
|
15
|
+
t.references :footprinter, polymorphic: true
|
|
16
|
+
t.timestamps null: false
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
add_index :footprints, [
|
|
19
|
-
add_index :footprints, [
|
|
19
|
+
add_index :footprints, %i[footprintable_id footprintable_type]
|
|
20
|
+
add_index :footprints, %i[footprinter_id footprinter_type]
|
|
20
21
|
|
|
21
|
-
create_table :users, :
|
|
22
|
+
create_table :users, force: true do |t|
|
|
22
23
|
t.string :name
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
create_table :not_users, :
|
|
26
|
+
create_table :not_users, force: true do |t|
|
|
26
27
|
t.string :name
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
create_table :footprintables, :
|
|
30
|
+
create_table :footprintables, force: true do |t|
|
|
30
31
|
t.string :name
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
create_table :second_footprintables, :
|
|
34
|
+
create_table :second_footprintables, force: true do |t|
|
|
34
35
|
t.string :name
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
create_table :not_footprintables, :
|
|
38
|
+
create_table :not_footprintables, force: true do |t|
|
|
38
39
|
t.string :name
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
DatabaseCleaner.strategy = :transaction
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
module Minitest
|
|
46
|
+
class Spec
|
|
47
|
+
include ActiveSupport::Testing::TimeHelpers
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
before :each do
|
|
50
|
+
DatabaseCleaner.start
|
|
51
|
+
end
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
after :each do
|
|
54
|
+
DatabaseCleaner.clean
|
|
55
|
+
end
|
|
52
56
|
end
|
|
53
57
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acts_as_footprintable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Toyoaki Oko
|
|
@@ -10,6 +10,40 @@ bindir: bin
|
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2022-01-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activerecord
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 5.0.0
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 7.1.0
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 5.0.0
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 7.1.0
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: database_cleaner
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
type: :development
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.0'
|
|
13
47
|
- !ruby/object:Gem::Dependency
|
|
14
48
|
name: rake
|
|
15
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -25,33 +59,75 @@ dependencies:
|
|
|
25
59
|
- !ruby/object:Gem::Version
|
|
26
60
|
version: '13.0'
|
|
27
61
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
62
|
+
name: rubocop
|
|
29
63
|
requirement: !ruby/object:Gem::Requirement
|
|
30
64
|
requirements:
|
|
31
65
|
- - "~>"
|
|
32
66
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
67
|
+
version: '1.24'
|
|
34
68
|
type: :development
|
|
35
69
|
prerelease: false
|
|
36
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
71
|
requirements:
|
|
38
72
|
- - "~>"
|
|
39
73
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
74
|
+
version: '1.24'
|
|
41
75
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
76
|
+
name: rubocop-minitest
|
|
43
77
|
requirement: !ruby/object:Gem::Requirement
|
|
44
78
|
requirements:
|
|
45
79
|
- - "~>"
|
|
46
80
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
81
|
+
version: '0.17'
|
|
48
82
|
type: :development
|
|
49
83
|
prerelease: false
|
|
50
84
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
85
|
requirements:
|
|
52
86
|
- - "~>"
|
|
53
87
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
88
|
+
version: '0.17'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rubocop-performance
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '1.13'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '1.13'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: rubocop-rake
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0.6'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0.6'
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: sqlite3
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '1.3'
|
|
124
|
+
type: :development
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '1.3'
|
|
55
131
|
description: Rails gem to allowing records to leave footprints
|
|
56
132
|
email: chariderpato@gmail.com
|
|
57
133
|
executables: []
|
|
@@ -61,6 +137,7 @@ files:
|
|
|
61
137
|
- ".github/workflows/gem-push.yml"
|
|
62
138
|
- ".github/workflows/test.yml"
|
|
63
139
|
- ".gitignore"
|
|
140
|
+
- ".rubocop.yml"
|
|
64
141
|
- Gemfile
|
|
65
142
|
- LICENSE.txt
|
|
66
143
|
- README.md
|
|
@@ -93,7 +170,8 @@ files:
|
|
|
93
170
|
homepage: https://github.com/patorash/acts_as_footprintable
|
|
94
171
|
licenses:
|
|
95
172
|
- MIT
|
|
96
|
-
metadata:
|
|
173
|
+
metadata:
|
|
174
|
+
rubygems_mfa_required: 'true'
|
|
97
175
|
post_install_message:
|
|
98
176
|
rdoc_options: []
|
|
99
177
|
require_paths:
|
|
@@ -102,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
102
180
|
requirements:
|
|
103
181
|
- - ">="
|
|
104
182
|
- !ruby/object:Gem::Version
|
|
105
|
-
version: '
|
|
183
|
+
version: '2.6'
|
|
106
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
185
|
requirements:
|
|
108
186
|
- - ">="
|