acts_as_footprintable 0.2.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +218 -0
- data/.gitignore +2 -0
- data/.rspec +3 -1
- data/Gemfile +3 -15
- data/README.md +4 -4
- data/Rakefile +1 -5
- data/acts_as_footprintable.gemspec +8 -7
- data/config.ru +9 -0
- data/gemfiles/rails_5.0.gemfile +6 -0
- data/gemfiles/rails_5.1.gemfile +6 -0
- data/gemfiles/rails_5.2.gemfile +6 -0
- data/gemfiles/rails_6.0.gemfile +6 -0
- data/gemfiles/rails_6.1.gemfile +6 -0
- data/lib/acts_as_footprintable.rb +0 -1
- data/lib/acts_as_footprintable/footprint.rb +6 -13
- data/lib/acts_as_footprintable/footprintable.rb +4 -9
- data/lib/acts_as_footprintable/footprinter.rb +6 -11
- data/lib/acts_as_footprintable/version.rb +1 -2
- data/lib/generators/acts_as_footprintable/migration/migration_generator.rb +11 -2
- data/lib/generators/acts_as_footprintable/migration/templates/active_record/migration.rb +4 -5
- data/spec/footprintable_spec.rb +24 -33
- data/spec/footprinter_spec.rb +20 -15
- data/spec/internal/config/database.yml +2 -0
- data/spec/spec_helper.rb +14 -4
- metadata +55 -22
- data/.travis.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a3c1fe11e9f93ed9d4f25697085f46cedc641c0bbad515aadfebd074e710ab4
|
4
|
+
data.tar.gz: 43d0572a3355ab1f3a45c6a3bbc46861ef9b9e8252bf949b3eb77ad3c70d36ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d0ad6b039d031835987b43d616a7901f048fd1a295d1e83403d251783de71e8505b207c41c571daa0a900169f6209d0b84c8f7c03520f6795983759c8db8dda
|
7
|
+
data.tar.gz: c9476e013836d614bbca4e586b2b779abd0cfb4561cbf3623c49c2fba7e10d2b6a57369282af6ff1fb86ab271dcf6037e5519a91e817bd98dc633e042dad31fa
|
@@ -0,0 +1,218 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
executors:
|
4
|
+
ruby:
|
5
|
+
parameters:
|
6
|
+
ruby_version:
|
7
|
+
default: '2.7.2'
|
8
|
+
type: enum
|
9
|
+
enum: ['2.5.8', '2.6.6', '2.7.2']
|
10
|
+
working_directory: ~/repo
|
11
|
+
docker:
|
12
|
+
- image: circleci/ruby:<< parameters.ruby_version >>-node-browsers
|
13
|
+
- image: circleci/postgres:11.2-alpine-postgis-ram
|
14
|
+
|
15
|
+
commands:
|
16
|
+
bundle_install:
|
17
|
+
parameters:
|
18
|
+
rails_version:
|
19
|
+
default: '6.1'
|
20
|
+
type: enum
|
21
|
+
enum: ['5.0', '5.1', '5.2', '6.0', '6.1']
|
22
|
+
steps:
|
23
|
+
- run: gem install bundler --version=2.1.4 -N
|
24
|
+
- run:
|
25
|
+
name: bundle install
|
26
|
+
command: |
|
27
|
+
export BUNDLE_GEMFILE=$PWD/gemfiles/rails_<< parameters.rails_version >>.gemfile
|
28
|
+
bundle check || bundle install --jobs=4 --retry=3
|
29
|
+
|
30
|
+
rspec:
|
31
|
+
parameters:
|
32
|
+
rails_version:
|
33
|
+
default: '6.1'
|
34
|
+
type: enum
|
35
|
+
enum: ['5.0', '5.1', '5.2', '6.0', '6.1']
|
36
|
+
steps:
|
37
|
+
- run:
|
38
|
+
name: run tests
|
39
|
+
command: |
|
40
|
+
export BUNDLE_GEMFILE=$PWD/gemfiles/rails_<< parameters.rails_version >>.gemfile
|
41
|
+
mkdir /tmp/test-results
|
42
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
43
|
+
circleci tests split --split-by=timings)"
|
44
|
+
|
45
|
+
bundle exec rspec \
|
46
|
+
--format progress \
|
47
|
+
--format RspecJunitFormatter \
|
48
|
+
--out /tmp/test-results/rspec.xml \
|
49
|
+
--format progress \
|
50
|
+
$TEST_FILES
|
51
|
+
|
52
|
+
run_test:
|
53
|
+
parameters:
|
54
|
+
rails_version:
|
55
|
+
default: '6.1'
|
56
|
+
type: enum
|
57
|
+
enum: ['5.0', '5.1', '5.2', '6.0', '6.1']
|
58
|
+
steps:
|
59
|
+
- checkout
|
60
|
+
- bundle_install:
|
61
|
+
rails_version: << parameters.rails_version >>
|
62
|
+
- rspec:
|
63
|
+
rails_version: << parameters.rails_version >>
|
64
|
+
# collect reports
|
65
|
+
- store_test_results:
|
66
|
+
path: /tmp/test-results
|
67
|
+
- store_artifacts:
|
68
|
+
path: /tmp/test-results
|
69
|
+
destination: test-results
|
70
|
+
|
71
|
+
jobs:
|
72
|
+
test:
|
73
|
+
parameters:
|
74
|
+
ruby_version:
|
75
|
+
type: enum
|
76
|
+
enum: ['2.5.8', '2.6.6', '2.7.2']
|
77
|
+
rails_version:
|
78
|
+
type: enum
|
79
|
+
enum: ['5.0', '5.1', '5.2', '6.0', '6.1']
|
80
|
+
executor:
|
81
|
+
name: ruby
|
82
|
+
ruby_version: << parameters.ruby_version >>
|
83
|
+
parallelism: 1
|
84
|
+
steps:
|
85
|
+
- run_test:
|
86
|
+
rails_version: << parameters.rails_version >>
|
87
|
+
|
88
|
+
release:
|
89
|
+
executor:
|
90
|
+
name: ruby
|
91
|
+
parallelism: 1
|
92
|
+
steps:
|
93
|
+
- checkout
|
94
|
+
- add_ssh_keys:
|
95
|
+
fingerprints:
|
96
|
+
- "ac:6c:e5:dc:f5:60:53:57:0c:60:d3:32:98:98:0e:30"
|
97
|
+
- run: gem install bundler --version=2.1.4 -N
|
98
|
+
- run:
|
99
|
+
name: bundle install
|
100
|
+
command: bundle check || bundle install --jobs=4 --retry=3
|
101
|
+
- run:
|
102
|
+
name: RubyGems.org | Set credential
|
103
|
+
command: |
|
104
|
+
mkdir -p ~/.gem
|
105
|
+
echo ":rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
|
106
|
+
chmod 0600 ~/.gem/credentials
|
107
|
+
- run:
|
108
|
+
name: Setup git
|
109
|
+
command: |
|
110
|
+
git config push.default current
|
111
|
+
git config user.email "chariderpato@gmail.com"
|
112
|
+
git config user.name "patorash"
|
113
|
+
- run:
|
114
|
+
name: rake release
|
115
|
+
command: |
|
116
|
+
set +e
|
117
|
+
filename=$(for n in *; do printf '%s\n' "$n"; done | grep gemspec)
|
118
|
+
gem_name=`ruby -e "require 'rubygems'; spec = Gem::Specification::load('${filename}'); puts spec.name"`
|
119
|
+
gem_version=`ruby -e "require 'rubygems'; spec = Gem::Specification::load('${filename}'); puts spec.version"`
|
120
|
+
gem list --prerelease --all --remote $gem_name \
|
121
|
+
| grep -E "^${gem_name}" \
|
122
|
+
| sed -e "s/^.*(\(.*\)).*\$/\1/" \
|
123
|
+
| grep -q -v $gem_version
|
124
|
+
result=$?
|
125
|
+
if [ $result = 0 ]; then
|
126
|
+
bundle exec rake build
|
127
|
+
bundle exec rake release
|
128
|
+
fi
|
129
|
+
- run:
|
130
|
+
name: Delete credentials
|
131
|
+
command: |
|
132
|
+
shred -u ~/.gem/credentials
|
133
|
+
|
134
|
+
workflows:
|
135
|
+
build:
|
136
|
+
jobs:
|
137
|
+
- test:
|
138
|
+
name: 'Ruby 2.5.8-Rails 5.0'
|
139
|
+
ruby_version: '2.5.8'
|
140
|
+
rails_version: '5.0'
|
141
|
+
- test:
|
142
|
+
name: 'Ruby 2.6.6-Rails 5.0'
|
143
|
+
ruby_version: '2.6.6'
|
144
|
+
rails_version: '5.0'
|
145
|
+
- test:
|
146
|
+
name: 'Ruby 2.7.2-Rails 5.0'
|
147
|
+
ruby_version: '2.7.2'
|
148
|
+
rails_version: '5.0'
|
149
|
+
- test:
|
150
|
+
name: 'Ruby 2.5.8-Rails 5.1'
|
151
|
+
ruby_version: '2.5.8'
|
152
|
+
rails_version: '5.1'
|
153
|
+
- test:
|
154
|
+
name: 'Ruby 2.6.6-Rails 5.1'
|
155
|
+
ruby_version: '2.6.6'
|
156
|
+
rails_version: '5.1'
|
157
|
+
- test:
|
158
|
+
name: 'Ruby 2.7.2-Rails 5.1'
|
159
|
+
ruby_version: '2.7.2'
|
160
|
+
rails_version: '5.1'
|
161
|
+
- test:
|
162
|
+
name: 'Ruby 2.5.8-Rails 5.2'
|
163
|
+
ruby_version: '2.5.8'
|
164
|
+
rails_version: '5.2'
|
165
|
+
- test:
|
166
|
+
name: 'Ruby 2.6.6-Rails 5.2'
|
167
|
+
ruby_version: '2.6.6'
|
168
|
+
rails_version: '5.2'
|
169
|
+
- test:
|
170
|
+
name: 'Ruby 2.7.2-Rails 5.2'
|
171
|
+
ruby_version: '2.7.2'
|
172
|
+
rails_version: '5.2'
|
173
|
+
- test:
|
174
|
+
name: 'Ruby 2.5.8-Rails 6.0'
|
175
|
+
ruby_version: '2.5.8'
|
176
|
+
rails_version: '6.0'
|
177
|
+
- test:
|
178
|
+
name: 'Ruby 2.6.6-Rails 6.0'
|
179
|
+
ruby_version: '2.6.6'
|
180
|
+
rails_version: '6.0'
|
181
|
+
- test:
|
182
|
+
name: 'Ruby 2.7.2-Rails 6.0'
|
183
|
+
ruby_version: '2.7.2'
|
184
|
+
rails_version: '6.1'
|
185
|
+
- test:
|
186
|
+
name: 'Ruby 2.5.8-Rails 6.1'
|
187
|
+
ruby_version: '2.5.8'
|
188
|
+
rails_version: '6.1'
|
189
|
+
- test:
|
190
|
+
name: 'Ruby 2.6.6-Rails 6.1'
|
191
|
+
ruby_version: '2.6.6'
|
192
|
+
rails_version: '6.1'
|
193
|
+
- test:
|
194
|
+
name: 'Ruby 2.7.2-Rails 6.1'
|
195
|
+
ruby_version: '2.7.2'
|
196
|
+
rails_version: '6.1'
|
197
|
+
- release:
|
198
|
+
context:
|
199
|
+
- rubygems.org
|
200
|
+
requires:
|
201
|
+
- 'Ruby 2.5.8-Rails 5.0'
|
202
|
+
- 'Ruby 2.6.6-Rails 5.0'
|
203
|
+
- 'Ruby 2.7.2-Rails 5.0'
|
204
|
+
- 'Ruby 2.5.8-Rails 5.1'
|
205
|
+
- 'Ruby 2.6.6-Rails 5.1'
|
206
|
+
- 'Ruby 2.7.2-Rails 5.1'
|
207
|
+
- 'Ruby 2.5.8-Rails 5.2'
|
208
|
+
- 'Ruby 2.6.6-Rails 5.2'
|
209
|
+
- 'Ruby 2.7.2-Rails 5.2'
|
210
|
+
- 'Ruby 2.5.8-Rails 6.0'
|
211
|
+
- 'Ruby 2.6.6-Rails 6.0'
|
212
|
+
- 'Ruby 2.7.2-Rails 6.0'
|
213
|
+
- 'Ruby 2.5.8-Rails 6.1'
|
214
|
+
- 'Ruby 2.6.6-Rails 6.1'
|
215
|
+
- 'Ruby 2.7.2-Rails 6.1'
|
216
|
+
filters:
|
217
|
+
branches:
|
218
|
+
only: master
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile
CHANGED
@@ -1,21 +1,9 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
source 'https://rubygems.org'
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
4
|
|
4
5
|
# Specify your gem's dependencies in acts_as_footprintable.gemspec
|
5
6
|
gemspec
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
rails = case rails_version
|
10
|
-
when 'master'
|
11
|
-
{ :github => 'rails/rails' }
|
12
|
-
when 'default'
|
13
|
-
'~> 3.2.0'
|
14
|
-
else
|
15
|
-
"~> #{rails_version}"
|
16
|
-
end
|
17
|
-
|
18
|
-
gem 'rails', rails
|
19
|
-
group :development do
|
20
|
-
gem 'combustion', github: 'patorash/combustion', branch: 'master'
|
21
|
-
end
|
8
|
+
gem 'rails'
|
9
|
+
gem 'pg'
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ActsAsFootprintable
|
2
|
-
[![
|
2
|
+
[![patorash](https://circleci.com/gh/patorash/acts_as_footprintable.svg?style=svg)](https://circleci.com/gh/patorash/acts_as_footprintable)
|
3
3
|
|
4
4
|
Acts As Footprintable is a Ruby Gem specifically written for Rails/ActiveRecord models.
|
5
5
|
The main goals of this gem are:
|
@@ -11,12 +11,12 @@ The main goals of this gem are:
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
### Rails
|
14
|
+
### Rails 5.x and 6.x
|
15
15
|
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'acts_as_footprintable', '~> 0.
|
19
|
+
gem 'acts_as_footprintable', '~> 0.6.0'
|
20
20
|
```
|
21
21
|
|
22
22
|
And then execute:
|
@@ -44,7 +44,7 @@ class Post < ActiveRecord::Base
|
|
44
44
|
acts_as_footprintable
|
45
45
|
end
|
46
46
|
|
47
|
-
@post = Post.create(:
|
47
|
+
@post = Post.create(name: 'my post!')
|
48
48
|
|
49
49
|
@post.leave_footprints @user
|
50
50
|
@post.footprints.size # => 1
|
data/Rakefile
CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_development_dependency '
|
24
|
-
spec.add_development_dependency '
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency '
|
27
|
-
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
22
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
23
|
+
spec.add_development_dependency 'timecop', '~> 0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'combustion', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'pry', '~> 0'
|
27
|
+
spec.add_development_dependency 'database_cleaner', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
|
28
29
|
end
|
data/config.ru
ADDED
@@ -1,19 +1,12 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module ActsAsFootprintable
|
3
2
|
class Footprint < ::ActiveRecord::Base
|
4
|
-
|
5
|
-
|
6
|
-
:footprinter_id, :footprinter_type,
|
7
|
-
:footprintable, :footprinter
|
8
|
-
end
|
3
|
+
belongs_to :footprintable, polymorphic: true
|
4
|
+
belongs_to :footprinter, polymorphic: true
|
9
5
|
|
10
|
-
|
11
|
-
|
6
|
+
scope :for_type, lambda{|klass| where(footprintable_type: klass.name)}
|
7
|
+
scope :by_type, lambda{|klass| where(footprinter_type: klass.name)}
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
validates :footprintable_id, :presence => true
|
17
|
-
validates :footprinter_id, :presence => true
|
9
|
+
validates :footprintable_id, presence: true
|
10
|
+
validates :footprinter_id, presence: true
|
18
11
|
end
|
19
12
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module ActsAsFootprintable
|
3
2
|
module Footprintable
|
4
3
|
|
5
4
|
def self.included(base)
|
6
5
|
base.class_eval do
|
7
|
-
has_many :footprints, :
|
6
|
+
has_many :footprints, class_name: 'ActsAsFootprintable::Footprint', as: :footprintable, dependent: :destroy do
|
8
7
|
def footprinters
|
9
8
|
includes(:footprinter).map(&:footprinter)
|
10
9
|
end
|
@@ -13,12 +12,8 @@ module ActsAsFootprintable
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def leave_footprints(footprinter)
|
16
|
-
footprint = ActsAsFootprintable::Footprint.new(:
|
17
|
-
|
18
|
-
true
|
19
|
-
else
|
20
|
-
false
|
21
|
-
end
|
15
|
+
footprint = ActsAsFootprintable::Footprint.new(footprintable: self, footprinter: footprinter)
|
16
|
+
footprint.save
|
22
17
|
end
|
23
18
|
|
24
19
|
def footprint_count
|
@@ -26,7 +21,7 @@ module ActsAsFootprintable
|
|
26
21
|
end
|
27
22
|
|
28
23
|
def footprint_count_between(range)
|
29
|
-
footprints.where(:
|
24
|
+
footprints.where(created_at: range).count
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module ActsAsFootprintable
|
3
2
|
module Footprinter
|
4
3
|
def self.included(base)
|
5
4
|
base.class_eval do
|
6
|
-
has_many :footprints, :
|
5
|
+
has_many :footprints, class_name: 'ActsAsFootprintable::Footprint', as: :footprinter, dependent: :destroy do
|
7
6
|
def footprintable
|
8
7
|
includes(:footprintable).map(&:footprintable)
|
9
8
|
end
|
@@ -12,12 +11,8 @@ module ActsAsFootprintable
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def leave_footprints(footprintable)
|
15
|
-
footprint = ActsAsFootprintable::Footprint.new(:
|
16
|
-
|
17
|
-
true
|
18
|
-
else
|
19
|
-
false
|
20
|
-
end
|
14
|
+
footprint = ActsAsFootprintable::Footprint.new(footprintable: footprintable, footprinter: self)
|
15
|
+
footprint.save
|
21
16
|
end
|
22
17
|
|
23
18
|
def access_histories_for(klass, limit=nil)
|
@@ -30,7 +25,7 @@ module ActsAsFootprintable
|
|
30
25
|
|
31
26
|
private
|
32
27
|
def get_access_history_records(target, limit=nil)
|
33
|
-
footprints.where(:
|
28
|
+
footprints.where(id: recent_footprint_ids(target, limit)).order("created_at DESC")
|
34
29
|
end
|
35
30
|
|
36
31
|
def table_name
|
@@ -39,8 +34,8 @@ module ActsAsFootprintable
|
|
39
34
|
|
40
35
|
def recent_footprint_ids(target, limit=nil)
|
41
36
|
recent_footprints = target.group("#{table_name}.footprintable_id, #{table_name}.footprintable_type").
|
42
|
-
select("#{table_name}.footprintable_id, #{table_name}.footprintable_type, MAX(#{table_name}.created_at)")
|
43
|
-
records = footprints.where("(#{table_name}.footprintable_id, #{table_name}.footprintable_type, #{table_name}.created_at) IN (#{recent_footprints.
|
37
|
+
select("#{table_name}.footprintable_id, #{table_name}.footprintable_type, MAX(#{table_name}.created_at) AS created_at")
|
38
|
+
records = footprints.where("(#{table_name}.footprintable_id, #{table_name}.footprintable_type, #{table_name}.created_at) IN (#{recent_footprints.to_sql})")
|
44
39
|
records = records.order("footprints.created_at desc")
|
45
40
|
records = records.limit(limit) unless limit.nil?
|
46
41
|
records.pluck(:id)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
require 'rails/generators/migration'
|
3
2
|
|
4
3
|
module ActsAsFootprintable
|
@@ -25,8 +24,18 @@ module ActsAsFootprintable
|
|
25
24
|
|
26
25
|
def create_migration_file
|
27
26
|
if self.class.orm_has_migration?
|
28
|
-
migration_template 'migration.rb', 'db/migrate/acts_as_footprintable_migration'
|
27
|
+
migration_template 'migration.rb', 'db/migrate/acts_as_footprintable_migration.rb', migration_version: migration_version
|
29
28
|
end
|
30
29
|
end
|
30
|
+
|
31
|
+
def migration_version
|
32
|
+
if over_rails5?
|
33
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def over_rails5?
|
38
|
+
Rails::VERSION::MAJOR >= 5
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
class ActsAsFootprintableMigration < ActiveRecord::Migration
|
1
|
+
class ActsAsFootprintableMigration < ActiveRecord::Migration<%= migration_version %>
|
3
2
|
def self.up
|
4
3
|
create_table :footprints do |t|
|
5
|
-
t.references :footprintable, :
|
6
|
-
t.references :footprinter, :
|
7
|
-
t.timestamps :
|
4
|
+
t.references :footprintable, polymorphic: true
|
5
|
+
t.references :footprinter, polymorphic: true
|
6
|
+
t.timestamps null: false
|
8
7
|
end
|
9
8
|
|
10
9
|
if ActiveRecord::VERSION::MAJOR < 4
|
data/spec/footprintable_spec.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe ActsAsFootprintable::Footprintable do
|
1
|
+
RSpec.describe ActsAsFootprintable::Footprintable, type: :model do
|
5
2
|
|
6
3
|
it "should not be a footprintable" do
|
7
4
|
expect(NotFootprintable).not_to be_footprintable
|
@@ -12,59 +9,55 @@ describe ActsAsFootprintable::Footprintable do
|
|
12
9
|
end
|
13
10
|
|
14
11
|
describe 'leave footprints by footprinter' do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@footprintable = Footprintable.create!(:name => 'a footprinting model')
|
21
|
-
@footprintable2 = Footprintable.create!(:name => 'a 2nd footprinting model')
|
22
|
-
end
|
12
|
+
let(:user) { User.create!(:name => 'i can footprint!') }
|
13
|
+
let(:user2) { User.create!(:name => 'a new person') }
|
14
|
+
let(:footprintable) { Footprintable.create!(:name => 'a footprinting model') }
|
15
|
+
let(:footprintable2) { Footprintable.create!(:name => 'a 2nd footprinting model') }
|
23
16
|
|
24
17
|
it "should be leave footprints" do
|
25
|
-
expect(
|
18
|
+
expect(footprintable.leave_footprints(user)).to be_truthy
|
26
19
|
end
|
27
20
|
|
28
21
|
it "足跡の数が増えていること" do
|
29
22
|
expect {
|
30
|
-
|
31
|
-
}.to change{
|
23
|
+
footprintable.leave_footprints user
|
24
|
+
}.to change { footprintable.footprint_count }.from(0).to(1)
|
32
25
|
end
|
33
26
|
|
34
27
|
it "10回アクセスしたら10になること" do
|
35
28
|
expect {
|
36
|
-
10.times {
|
37
|
-
}.to change{
|
29
|
+
10.times { footprintable.leave_footprints user }
|
30
|
+
}.to change { footprintable.footprint_count }.from(0).to(10)
|
38
31
|
end
|
39
32
|
|
40
33
|
it "複数人でアクセスしたら合計されること" do
|
41
34
|
expect {
|
42
|
-
5.times {
|
43
|
-
5.times {
|
44
|
-
}.to change{
|
35
|
+
5.times { footprintable.leave_footprints user }
|
36
|
+
5.times { footprintable.leave_footprints user2 }
|
37
|
+
}.to change { footprintable.footprint_count }.from(0).to(10)
|
45
38
|
end
|
46
39
|
|
47
40
|
describe "期間指定をする" do
|
48
41
|
before do
|
49
42
|
(1..30).each do |day|
|
50
|
-
Timecop.travel(Time.parse("2013
|
51
|
-
5.times {
|
43
|
+
Timecop.travel(Time.parse("2013-09-#{day}")) do
|
44
|
+
5.times { footprintable.leave_footprints user }
|
52
45
|
end
|
53
46
|
end
|
54
47
|
end
|
55
48
|
|
56
49
|
context "1週間の場合" do
|
57
50
|
it "35の足跡があること" do
|
58
|
-
Timecop.travel(Time.parse("2013
|
59
|
-
expect(
|
51
|
+
Timecop.travel(Time.parse("2013-09-30 10:00:00")) do
|
52
|
+
expect(footprintable.footprint_count_between(1.week.ago..Time.now)).to eq 35
|
60
53
|
end
|
61
54
|
end
|
62
55
|
end
|
63
56
|
|
64
57
|
context "1ヶ月の場合" do
|
65
58
|
it "150の足跡があること" do
|
66
|
-
Timecop.travel(Time.parse("2013
|
67
|
-
expect(
|
59
|
+
Timecop.travel(Time.parse("2013-09-30 10:00:00")) do
|
60
|
+
expect(footprintable.footprint_count_between(1.month.ago..Time.now)).to eq 150
|
68
61
|
end
|
69
62
|
end
|
70
63
|
end
|
@@ -72,24 +65,22 @@ describe ActsAsFootprintable::Footprintable do
|
|
72
65
|
end
|
73
66
|
|
74
67
|
describe "アクセスランキングを作成" do
|
75
|
-
|
76
|
-
@user = User.create!(:name => 'i can footprint!')
|
77
|
-
end
|
68
|
+
let(:user) { User.create!(:name => 'i can footprint!') }
|
78
69
|
|
79
70
|
context "件数と期間を制限" do
|
80
71
|
before do
|
81
72
|
(1..30).each do |index|
|
82
|
-
Timecop.travel(Time.parse("2013
|
73
|
+
Timecop.travel(Time.parse("2013-09-#{index}")) do
|
83
74
|
footprintable = Footprintable.create!(:name => "Footprintable#{index}")
|
84
|
-
index.times {footprintable.leave_footprints
|
75
|
+
index.times { footprintable.leave_footprints user }
|
85
76
|
end
|
86
77
|
end
|
87
78
|
end
|
88
79
|
subject do
|
89
|
-
month = Time.new(2013,9,1)
|
80
|
+
month = Time.new(2013, 9, 1)
|
90
81
|
Footprintable.access_ranking(month.beginning_of_month...1.week.since(month), 5)
|
91
82
|
end
|
92
|
-
it { is_expected.to eq ({7 => 7, 6 => 6, 5 => 5, 4 => 4, 3 => 3 }) }
|
83
|
+
it { is_expected.to eq ({ 7 => 7, 6 => 6, 5 => 5, 4 => 4, 3 => 3 }) }
|
93
84
|
it '5件取得できること' do
|
94
85
|
expect(subject.count).to eq 5
|
95
86
|
end
|
data/spec/footprinter_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
1
|
require 'acts_as_footprintable/footprinter'
|
4
2
|
|
5
|
-
describe ActsAsFootprintable::Footprinter do
|
3
|
+
RSpec.describe ActsAsFootprintable::Footprinter, type: :model do
|
6
4
|
|
7
5
|
it "should not be a footprinter" do
|
8
6
|
expect(NotUser).not_to be_footprinter
|
@@ -13,43 +11,50 @@ describe ActsAsFootprintable::Footprinter do
|
|
13
11
|
end
|
14
12
|
|
15
13
|
describe "ユーザーのアクセス履歴を" do
|
14
|
+
let!(:user_1) { User.create!(name: "user_1") }
|
16
15
|
before do
|
17
|
-
@user = User.create!(:name => "user")
|
18
16
|
(1..5).each do |index|
|
19
|
-
footprintable = Footprintable.create!(:
|
20
|
-
second_footprintable = SecondFootprintable.create!(:
|
17
|
+
footprintable = Footprintable.create!(name: "footprintable#{index}")
|
18
|
+
second_footprintable = SecondFootprintable.create!(name: "second_footprintable#{index}")
|
21
19
|
3.times do
|
22
|
-
footprintable.leave_footprints
|
23
|
-
second_footprintable.leave_footprints
|
20
|
+
footprintable.leave_footprints user_1
|
21
|
+
second_footprintable.leave_footprints user_1
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
context "対象のモデル毎に" do
|
29
27
|
it "取得できること" do
|
30
|
-
expect(
|
31
|
-
expect(
|
28
|
+
expect(user_1.access_histories_for(Footprintable).count).to eq 5
|
29
|
+
expect(user_1.access_histories_for(Footprintable).map { |footprint| footprint.footprintable.name }).to eq (1..5).to_a.reverse.map { |index| "footprintable#{index}" }
|
32
30
|
end
|
33
31
|
|
34
32
|
it "件数を絞り込めること" do
|
35
|
-
expect(
|
36
|
-
expect(
|
33
|
+
expect(user_1.access_histories_for(Footprintable, 3).count).to eq 3
|
34
|
+
expect(user_1.access_histories_for(Footprintable, 3).map { |footprint| footprint.footprintable.name }).to eq (3..5).to_a.reverse.map { |index| "footprintable#{index}" }
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
38
|
context "全てのモデルを通じて" do
|
41
39
|
it "取得できること" do
|
42
|
-
expect(
|
40
|
+
expect(user_1.access_histories.count).to eq 10
|
43
41
|
footprintable_names = (1..5).to_a.reverse.inject([]) do |results, index|
|
44
42
|
results.push "second_footprintable#{index}"
|
45
43
|
results.push "footprintable#{index}"
|
46
44
|
results
|
47
45
|
end
|
48
|
-
expect(
|
46
|
+
expect(user_1.access_histories.map { |footprint| footprint.footprintable.name }).to eq footprintable_names
|
49
47
|
end
|
50
48
|
|
51
49
|
it "件数を絞り込める事" do
|
52
|
-
expect(
|
50
|
+
expect(user_1.access_histories(3).count).to eq 3
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'アクセス履歴のないユーザーの場合' do
|
55
|
+
let!(:user_2) { User.create!(:name => "user_2") }
|
56
|
+
it '件数が0件であること' do
|
57
|
+
expect(user_2.access_histories_for(Footprintable).count).to eq 0
|
53
58
|
end
|
54
59
|
end
|
55
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,21 +2,31 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'combustion'
|
5
|
-
require 'database_cleaner'
|
5
|
+
require 'database_cleaner/active_record'
|
6
6
|
require 'timecop'
|
7
|
+
require 'pry'
|
7
8
|
|
8
9
|
Combustion.initialize! :active_record
|
9
10
|
|
10
11
|
RSpec.configure do |config|
|
11
|
-
|
12
|
-
config.
|
12
|
+
# Enable flags like --only-failures and --next-failure
|
13
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
13
14
|
|
14
|
-
|
15
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
16
|
+
config.disable_monkey_patching!
|
17
|
+
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
|
22
|
+
config.before(:suite) do
|
15
23
|
DatabaseCleaner.strategy = :truncation
|
16
24
|
end
|
25
|
+
|
17
26
|
config.before :each do
|
18
27
|
DatabaseCleaner.start
|
19
28
|
end
|
29
|
+
|
20
30
|
config.after :each do
|
21
31
|
DatabaseCleaner.clean
|
22
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_footprintable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toyoaki Oko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,68 +16,82 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
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: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: timecop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.0
|
61
|
+
version: '3.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.0
|
68
|
+
version: '3.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: combustion
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '1.3'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '1.3'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: pry
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
@@ -86,28 +100,48 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: '2.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec_junit_formatter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.4.1
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
124
|
+
version: 0.4.1
|
97
125
|
description: Rails gem to allowing records to leave footprints
|
98
126
|
email: chariderpato@gmail.com
|
99
127
|
executables: []
|
100
128
|
extensions: []
|
101
129
|
extra_rdoc_files: []
|
102
130
|
files:
|
131
|
+
- ".circleci/config.yml"
|
103
132
|
- ".gitignore"
|
104
133
|
- ".rspec"
|
105
|
-
- ".travis.yml"
|
106
134
|
- Gemfile
|
107
135
|
- LICENSE.txt
|
108
136
|
- README.md
|
109
137
|
- Rakefile
|
110
138
|
- acts_as_footprintable.gemspec
|
139
|
+
- config.ru
|
140
|
+
- gemfiles/rails_5.0.gemfile
|
141
|
+
- gemfiles/rails_5.1.gemfile
|
142
|
+
- gemfiles/rails_5.2.gemfile
|
143
|
+
- gemfiles/rails_6.0.gemfile
|
144
|
+
- gemfiles/rails_6.1.gemfile
|
111
145
|
- lib/acts_as_footprintable.rb
|
112
146
|
- lib/acts_as_footprintable/extenders/footprintable.rb
|
113
147
|
- lib/acts_as_footprintable/extenders/footprinter.rb
|
@@ -147,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
181
|
- !ruby/object:Gem::Version
|
148
182
|
version: '0'
|
149
183
|
requirements: []
|
150
|
-
|
151
|
-
rubygems_version: 2.5.1
|
184
|
+
rubygems_version: 3.1.4
|
152
185
|
signing_key:
|
153
186
|
specification_version: 4
|
154
187
|
summary: Rails gem to allowing records to leave footprints
|