acts_as_footprintable 0.5.0 → 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 -25
- data/README.md +4 -4
- data/Rakefile +1 -5
- data/acts_as_footprintable.gemspec +6 -5
- 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 +4 -9
- data/lib/acts_as_footprintable/version.rb +1 -2
- data/lib/generators/acts_as_footprintable/migration/migration_generator.rb +3 -4
- data/lib/generators/acts_as_footprintable/migration/templates/active_record/migration.rb +3 -4
- data/spec/footprintable_spec.rb +24 -33
- data/spec/footprinter_spec.rb +7 -9
- data/spec/internal/config/database.yml +2 -0
- data/spec/spec_helper.rb +13 -4
- metadata +35 -28
- data/.travis.yml +0 -33
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,31 +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
|
-
when 'master'
|
10
|
-
{ :github => 'rails/rails' }
|
11
|
-
when 'default'
|
12
|
-
'~> 3.2.0'
|
13
|
-
else
|
14
|
-
"~> #{rails_version}"
|
15
|
-
end
|
16
|
-
|
17
|
-
gem 'rails', rails
|
18
|
-
group :development do
|
19
|
-
if rails_version == 'default' ||
|
20
|
-
(Gem::Version.correct?(rails_version) && Gem::Version.new(rails_version) < Gem::Version.new("4.0.0"))
|
21
|
-
# rails < 4 needs combustion v0.5.2 (does not work with v0.5.3)
|
22
|
-
# An error occurred while loading ./spec/footprinter_spec.rb.
|
23
|
-
# Failure/Error: Combustion.initialize! :active_record
|
24
|
-
#
|
25
|
-
# PG::ConnectionBad:
|
26
|
-
# FATAL: database "acts_as_footprintable" does not exist
|
27
|
-
gem 'combustion', "0.5.2"
|
28
|
-
else
|
29
|
-
gem 'combustion'
|
30
|
-
end
|
31
|
-
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 'bundler', '~> 1
|
22
|
-
spec.add_development_dependency 'rake', '
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
|
24
|
-
spec.add_development_dependency 'pg', '~> 0'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
22
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
25
23
|
spec.add_development_dependency 'timecop', '~> 0'
|
26
|
-
spec.add_development_dependency '
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'combustion', '~> 1.3'
|
27
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
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
require 'rails/generators/migration'
|
3
2
|
|
4
3
|
module ActsAsFootprintable
|
@@ -30,13 +29,13 @@ module ActsAsFootprintable
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def migration_version
|
33
|
-
if
|
32
|
+
if over_rails5?
|
34
33
|
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
def
|
39
|
-
Rails
|
37
|
+
def over_rails5?
|
38
|
+
Rails::VERSION::MAJOR >= 5
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
# coding: utf-8
|
2
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,11 +11,11 @@ describe ActsAsFootprintable::Footprinter do
|
|
13
11
|
end
|
14
12
|
|
15
13
|
describe "ユーザーのアクセス履歴を" do
|
16
|
-
let!(:user_1) { User.create!(:
|
14
|
+
let!(:user_1) { User.create!(name: "user_1") }
|
17
15
|
before do
|
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
20
|
footprintable.leave_footprints user_1
|
23
21
|
second_footprintable.leave_footprints user_1
|
@@ -28,12 +26,12 @@ describe ActsAsFootprintable::Footprinter do
|
|
28
26
|
context "対象のモデル毎に" do
|
29
27
|
it "取得できること" do
|
30
28
|
expect(user_1.access_histories_for(Footprintable).count).to eq 5
|
31
|
-
expect(user_1.access_histories_for(Footprintable).map{|footprint| footprint.footprintable.name}).to eq (1..5).to_a.reverse.map{|index| "footprintable#{index}"}
|
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
33
|
expect(user_1.access_histories_for(Footprintable, 3).count).to eq 3
|
36
|
-
expect(user_1.access_histories_for(Footprintable, 3).map{|footprint| footprint.footprintable.name}).to eq (3..5).to_a.reverse.map{|index| "footprintable#{index}"}
|
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
|
|
@@ -45,7 +43,7 @@ describe ActsAsFootprintable::Footprinter do
|
|
45
43
|
results.push "footprintable#{index}"
|
46
44
|
results
|
47
45
|
end
|
48
|
-
expect(user_1.access_histories.map{|footprint| footprint.footprintable.name}).to eq footprintable_names
|
46
|
+
expect(user_1.access_histories.map { |footprint| footprint.footprintable.name }).to eq footprintable_names
|
49
47
|
end
|
50
48
|
|
51
49
|
it "件数を絞り込める事" do
|
data/spec/spec_helper.rb
CHANGED
@@ -2,22 +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
7
|
require 'pry'
|
8
8
|
|
9
9
|
Combustion.initialize! :active_record
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
|
-
|
13
|
-
config.
|
12
|
+
# Enable flags like --only-failures and --next-failure
|
13
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
14
14
|
|
15
|
-
|
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
|
16
23
|
DatabaseCleaner.strategy = :truncation
|
17
24
|
end
|
25
|
+
|
18
26
|
config.before :each do
|
19
27
|
DatabaseCleaner.start
|
20
28
|
end
|
29
|
+
|
21
30
|
config.after :each do
|
22
31
|
DatabaseCleaner.clean
|
23
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,16 +16,30 @@ 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
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: timecop
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
@@ -45,9 +59,6 @@ dependencies:
|
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '3.0'
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 3.0.0
|
51
62
|
type: :development
|
52
63
|
prerelease: false
|
53
64
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -55,25 +66,22 @@ dependencies:
|
|
55
66
|
- - "~>"
|
56
67
|
- !ruby/object:Gem::Version
|
57
68
|
version: '3.0'
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 3.0.0
|
61
69
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
70
|
+
name: combustion
|
63
71
|
requirement: !ruby/object:Gem::Requirement
|
64
72
|
requirements:
|
65
73
|
- - "~>"
|
66
74
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
75
|
+
version: '1.3'
|
68
76
|
type: :development
|
69
77
|
prerelease: false
|
70
78
|
version_requirements: !ruby/object:Gem::Requirement
|
71
79
|
requirements:
|
72
80
|
- - "~>"
|
73
81
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
82
|
+
version: '1.3'
|
75
83
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
84
|
+
name: pry
|
77
85
|
requirement: !ruby/object:Gem::Requirement
|
78
86
|
requirements:
|
79
87
|
- - "~>"
|
@@ -92,48 +100,48 @@ dependencies:
|
|
92
100
|
requirements:
|
93
101
|
- - "~>"
|
94
102
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: 1.0.1
|
103
|
+
version: '2.0'
|
99
104
|
type: :development
|
100
105
|
prerelease: false
|
101
106
|
version_requirements: !ruby/object:Gem::Requirement
|
102
107
|
requirements:
|
103
108
|
- - "~>"
|
104
109
|
- !ruby/object:Gem::Version
|
105
|
-
version: '
|
106
|
-
- - ">="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: 1.0.1
|
110
|
+
version: '2.0'
|
109
111
|
- !ruby/object:Gem::Dependency
|
110
|
-
name:
|
112
|
+
name: rspec_junit_formatter
|
111
113
|
requirement: !ruby/object:Gem::Requirement
|
112
114
|
requirements:
|
113
115
|
- - "~>"
|
114
116
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
117
|
+
version: 0.4.1
|
116
118
|
type: :development
|
117
119
|
prerelease: false
|
118
120
|
version_requirements: !ruby/object:Gem::Requirement
|
119
121
|
requirements:
|
120
122
|
- - "~>"
|
121
123
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
124
|
+
version: 0.4.1
|
123
125
|
description: Rails gem to allowing records to leave footprints
|
124
126
|
email: chariderpato@gmail.com
|
125
127
|
executables: []
|
126
128
|
extensions: []
|
127
129
|
extra_rdoc_files: []
|
128
130
|
files:
|
131
|
+
- ".circleci/config.yml"
|
129
132
|
- ".gitignore"
|
130
133
|
- ".rspec"
|
131
|
-
- ".travis.yml"
|
132
134
|
- Gemfile
|
133
135
|
- LICENSE.txt
|
134
136
|
- README.md
|
135
137
|
- Rakefile
|
136
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
|
137
145
|
- lib/acts_as_footprintable.rb
|
138
146
|
- lib/acts_as_footprintable/extenders/footprintable.rb
|
139
147
|
- lib/acts_as_footprintable/extenders/footprinter.rb
|
@@ -173,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
181
|
- !ruby/object:Gem::Version
|
174
182
|
version: '0'
|
175
183
|
requirements: []
|
176
|
-
|
177
|
-
rubygems_version: 2.6.13
|
184
|
+
rubygems_version: 3.1.4
|
178
185
|
signing_key:
|
179
186
|
specification_version: 4
|
180
187
|
summary: Rails gem to allowing records to leave footprints
|
data/.travis.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.4.2
|
4
|
-
- 2.3.4
|
5
|
-
- 2.2.7
|
6
|
-
- 2.1.10
|
7
|
-
env:
|
8
|
-
- "RAILS_VERSION=5.1.4"
|
9
|
-
- "RAILS_VERSION=5.0.0"
|
10
|
-
- "RAILS_VERSION=4.2.8"
|
11
|
-
- "RAILS_VERSION=4.2.0"
|
12
|
-
- "RAILS_VERSION=4.1.0"
|
13
|
-
- "RAILS_VERSION=4.0.0"
|
14
|
-
- "RAILS_VERSION=3.2.0"
|
15
|
-
branches:
|
16
|
-
only:
|
17
|
-
- master
|
18
|
-
- travis
|
19
|
-
|
20
|
-
matrix:
|
21
|
-
exclude:
|
22
|
-
- rvm: 2.1.10
|
23
|
-
env: "RAILS_VERSION=5.1.4"
|
24
|
-
- rvm: 2.1.10
|
25
|
-
env: "RAILS_VERSION=5.0.0"
|
26
|
-
- rvm: 2.4.2
|
27
|
-
env: "RAILS_VERSION=4.2.0"
|
28
|
-
- rvm: 2.4.2
|
29
|
-
env: "RAILS_VERSION=4.1.0"
|
30
|
-
- rvm: 2.4.2
|
31
|
-
env: "RAILS_VERSION=4.0.0"
|
32
|
-
- rvm: 2.4.2
|
33
|
-
env: "RAILS_VERSION=3.2.0"
|