acts_as_footprintable 0.3.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/gem-push.yml +30 -0
  3. data/.github/workflows/test.yml +42 -0
  4. data/.gitignore +18 -20
  5. data/Gemfile +3 -14
  6. data/README.md +6 -8
  7. data/Rakefile +9 -7
  8. data/acts_as_footprintable.gemspec +3 -7
  9. data/config.ru +9 -0
  10. data/gemfiles/rails_5.0.gemfile +6 -0
  11. data/gemfiles/rails_5.1.gemfile +6 -0
  12. data/gemfiles/rails_5.2.gemfile +6 -0
  13. data/gemfiles/rails_6.0.gemfile +6 -0
  14. data/gemfiles/rails_6.1.gemfile +6 -0
  15. data/gemfiles/rails_7.0.gemfile +6 -0
  16. data/lib/acts_as_footprintable/footprint.rb +6 -13
  17. data/lib/acts_as_footprintable/footprintable.rb +4 -9
  18. data/lib/acts_as_footprintable/footprinter.rb +5 -17
  19. data/lib/acts_as_footprintable/version.rb +1 -2
  20. data/lib/acts_as_footprintable.rb +0 -1
  21. data/lib/generators/acts_as_footprintable/migration/migration_generator.rb +11 -2
  22. data/lib/generators/acts_as_footprintable/migration/templates/active_record/migration.rb +4 -5
  23. data/test/footprintable_test.rb +96 -0
  24. data/{spec/footprinter_spec.rb → test/footprinter_test.rb} +18 -19
  25. data/{spec → test}/internal/app/models/footprintable.rb +0 -0
  26. data/{spec → test}/internal/app/models/not_footprintable.rb +0 -0
  27. data/{spec → test}/internal/app/models/not_user.rb +0 -0
  28. data/{spec → test}/internal/app/models/second_footprintable.rb +0 -0
  29. data/{spec → test}/internal/app/models/user.rb +0 -0
  30. data/{spec/internal/db/schema.rb → test/test_helper.rb} +23 -1
  31. metadata +35 -77
  32. data/.rspec +0 -1
  33. data/.travis.yml +0 -16
  34. data/spec/footprintable_spec.rb +0 -98
  35. data/spec/internal/config/database.yml +0 -5
  36. data/spec/internal/log/.gitignore +0 -1
  37. data/spec/spec_helper.rb +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '0836653de448c2d10bb14e4e2d3bd6f0dc584ce3'
4
- data.tar.gz: f8a02be5d569784ff93fe363774e1e3de4fd8900
2
+ SHA256:
3
+ metadata.gz: 0a242404e9828c149fcb0df3ca811377e6209e3486e15c2d38f7281ae56a78cd
4
+ data.tar.gz: 59b66fbd5006dea2eb60561f46faa50d70f013dfa779ebbb6df12ae7acc78ae7
5
5
  SHA512:
6
- metadata.gz: a3b349f2dafb4fb541669e2944c9737c774ca75ac380cd578ddab47db8fb489d3b2209a228a334ec655d5dab3453191e7dbf9cbf9db85975d1d58568fe61ba6d
7
- data.tar.gz: e61673ab9a1e77f4881ee3dbe6719319eba203b3d4d5e7a8fe77767a7702eb1ff8b22b4c3fd8af430fa89062c4b159a66c16cf933bc997442d9bb874a69f9e35
6
+ metadata.gz: d58d23cb349e23dba9370d87536a7f4d530e4358f2d1d5b5d61ebb1c00fc73eaf259a4990665a8bb9068da50e90b76298404f6da00d1824533a4d6a5b840cb2a
7
+ data.tar.gz: 6af3b769f4c2cb0fe47b4c11a3142a7c246b64ddff2933de3b5a04411eef1237d8339fc7a51516a9ef0b15b63d508fce202854574a8c1c940c8458656d2ddbeb
@@ -0,0 +1,30 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ build:
8
+ name: Build + Publish
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: read
12
+ packages: write
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build *.gemspec
28
+ gem push *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,42 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: ['2.6', '2.7', '3.0', '3.1']
15
+ gemfile: ['rails_5.0', 'rails_5.1', 'rails_5.2', 'rails_6.0', 'rails_6.1', 'rails_7.0']
16
+ exclude:
17
+ - ruby: '2.6'
18
+ gemfile: 'rails_7.0'
19
+ - ruby: '3.0'
20
+ gemfile: 'rails_5.0'
21
+ - ruby: '3.0'
22
+ gemfile: 'rails_5.1'
23
+ - ruby: '3.0'
24
+ gemfile: 'rails_5.2'
25
+ - ruby: '3.1'
26
+ gemfile: 'rails_5.0'
27
+ - ruby: '3.1'
28
+ gemfile: 'rails_5.1'
29
+ - ruby: '3.1'
30
+ gemfile: 'rails_5.2'
31
+ env:
32
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
33
+
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ bundler-cache: true
41
+ - name: Run tests
42
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -1,21 +1,19 @@
1
- *.iml
2
- .DS_Store
3
- .idea
4
- *.gem
5
- *.rbc
6
- .bundle
7
- .config
8
- .yardoc
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /log/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .ruby-version
9
14
  Gemfile.lock
10
- InstalledFiles
11
- _yardoc
12
- coverage
13
- doc/
14
- lib/bundler/man
15
- pkg
16
- rdoc
17
- spec/reports
18
- test/tmp
19
- test/version_tmp
20
- tmp
21
- *.log
15
+ .circleci/config.processed.yml
16
+
17
+ /gemfiles/*.gemfile.lock
18
+ /gemfiles/.bundle
19
+ *.sqlite3
data/Gemfile CHANGED
@@ -1,20 +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
- rails_version = ENV['RAILS_VERSION'] || 'default'
8
- rails = case rails_version
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
- gem 'combustion', '~> 0.5'
20
- end
8
+ gem 'rails'
9
+ gem 'sqlite3'
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # ActsAsFootprintable
2
- [![Build Status](https://travis-ci.org/patorash/acts_as_footprintable.png)](https://travis-ci.org/patorash/acts_as_footprintable)
2
+
3
+ [![Test](https://github.com/patorash/acts_as_footprintable/actions/workflows/test.yml/badge.svg)](https://github.com/patorash/acts_as_footprintable/actions/workflows/test.yml)
3
4
 
4
5
  Acts As Footprintable is a Ruby Gem specifically written for Rails/ActiveRecord models.
5
6
  The main goals of this gem are:
@@ -11,12 +12,12 @@ The main goals of this gem are:
11
12
 
12
13
  ## Installation
13
14
 
14
- ### Rails 3.2 and 4.0+
15
+ ### Rails 5.x, 6.x and 7.0
15
16
 
16
17
  Add this line to your application's Gemfile:
17
18
 
18
19
  ```ruby
19
- gem 'acts_as_footprintable', '~> 0.1.0'
20
+ gem 'acts_as_footprintable', '~> 0.6.0'
20
21
  ```
21
22
 
22
23
  And then execute:
@@ -44,7 +45,7 @@ class Post < ActiveRecord::Base
44
45
  acts_as_footprintable
45
46
  end
46
47
 
47
- @post = Post.create(:name => 'my post!')
48
+ @post = Post.create(name: 'my post!')
48
49
 
49
50
  @post.leave_footprints @user
50
51
  @post.footprints.size # => 1
@@ -91,10 +92,7 @@ post_access_histories = @user.access_histories_for(Post, 10)
91
92
 
92
93
  ## Testing
93
94
 
94
- All tests follow the RSpec format and located in the spec directory.
95
- They can be run with:
96
-
97
- $ rake spec
95
+ $ bundle exec rake
98
96
 
99
97
  ## Contributing
100
98
 
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- # coding: utf-8
2
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
3
 
4
- require 'rspec/core/rake_task'
4
+ task :default => [:test]
5
5
 
6
- desc "Run specs"
7
- RSpec::Core::RakeTask.new(:spec)
8
-
9
- desc 'Default: run specs.'
10
- task :default => :spec
6
+ Rake::TestTask.new do |test|
7
+ test.libs << 'lib'
8
+ test.libs << 'test'
9
+ test.test_files = Dir['test/**/*_test.rb']
10
+ test.warning = false
11
+ # test.verbose = true
12
+ end
@@ -18,11 +18,7 @@ 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.3"
22
- spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rspec', ">= 3.0.0"
24
- spec.add_development_dependency 'pg'
25
- spec.add_development_dependency 'timecop'
26
- spec.add_development_dependency 'database_cleaner', "~> 1.0.1"
27
- #spec.add_development_dependency 'combustion', '~> 0.5.1'
21
+ spec.add_development_dependency 'rake', '~> 13.0'
22
+ spec.add_development_dependency 'timecop', '~> 0'
23
+ spec.add_development_dependency 'database_cleaner', '~> 2.0'
28
24
  end
data/config.ru ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+
6
+ Bundler.require :default, :development
7
+
8
+ Combustion.initialize! :all
9
+ run Combustion::Application
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.0.0'
4
+ gem 'sqlite3', '~> 1.3.0'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.1.0'
4
+ gem 'sqlite3', '~> 1.3.0'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.2.0'
4
+ gem 'sqlite3', '~> 1.4'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 6.0.0'
4
+ gem 'sqlite3', '~> 1.4'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 6.1.0'
4
+ gem 'sqlite3', '~> 1.4'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 7.0.1'
4
+ gem 'sqlite3', '~> 1.4'
5
+
6
+ gemspec path: '../'
@@ -1,19 +1,12 @@
1
- # coding: utf-8
2
1
  module ActsAsFootprintable
3
2
  class Footprint < ::ActiveRecord::Base
4
- if ::ActiveRecord::VERSION::MAJOR < 4
5
- attr_accessible :footprintable_id, :footprintable_type,
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
- belongs_to :footprintable, :polymorphic => true
11
- belongs_to :footprinter, :polymorphic => true
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
- scope :for_type, lambda{|klass| where(:footprintable_type => klass.name)}
14
- scope :by_type, lambda{|klass| where(:footprinter_type => klass.name)}
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, :class_name => 'ActsAsFootprintable::Footprint', :as => :footprintable, :dependent => :destroy do
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(:footprintable => self, :footprinter => footprinter)
17
- if footprint.save
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(:created_at => range).count
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, :class_name => 'ActsAsFootprintable::Footprint', :as => :footprinter, :dependent => :destroy do
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(:footprintable => footprintable, :footprinter => self)
16
- if footprint.save
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(:id => recent_footprint_ids(target, limit)).order("created_at DESC")
28
+ footprints.where(id: recent_footprint_ids(target, limit)).order("created_at DESC")
34
29
  end
35
30
 
36
31
  def table_name
@@ -40,14 +35,7 @@ module ActsAsFootprintable
40
35
  def recent_footprint_ids(target, limit=nil)
41
36
  recent_footprints = target.group("#{table_name}.footprintable_id, #{table_name}.footprintable_type").
42
37
  select("#{table_name}.footprintable_id, #{table_name}.footprintable_type, MAX(#{table_name}.created_at) AS created_at")
43
- recent_footprints_conditions = recent_footprints.map{ |recent_footprint| recent_footprint.attributes.select{ |_, v| !v.nil?} }
44
- return [] if recent_footprints_conditions.first.nil?
45
-
46
- columns = recent_footprints_conditions.first.keys.map{|column| "#{table_name}.#{column}" }.join(',')
47
- values = recent_footprints_conditions.map { |row|
48
- "(#{row.values.map{|value| ActiveRecord::Base::sanitize(value)}.join(',')})"
49
- }.join(',')
50
- records = footprints.where("(#{columns}) IN (#{values})")
38
+ records = footprints.where("(#{table_name}.footprintable_id, #{table_name}.footprintable_type, #{table_name}.created_at) IN (#{recent_footprints.to_sql})")
51
39
  records = records.order("footprints.created_at desc")
52
40
  records = records.limit(limit) unless limit.nil?
53
41
  records.pluck(:id)
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  module ActsAsFootprintable
3
- VERSION = "0.3.1"
2
+ VERSION = '0.6.1'
4
3
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  require 'active_record'
3
2
  require 'active_support/inflector'
4
3
 
@@ -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
- # coding: utf-8
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, :polymorphic => true
6
- t.references :footprinter, :polymorphic => true
7
- t.timestamps :null => false
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
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+ require 'acts_as_footprintable/footprintable'
3
+
4
+ describe ActsAsFootprintable::Footprintable do
5
+
6
+ it "should not be a footprintable" do
7
+ expect(NotFootprintable).wont_be :footprintable?
8
+ end
9
+
10
+ it "should be a footprintable" do
11
+ expect(Footprintable).must_be :footprintable?
12
+ end
13
+
14
+ describe 'leave footprints by footprinter' do
15
+ let(:user) { User.create!(:name => 'i can footprint!') }
16
+ let(:user2) { User.create!(:name => 'a new person') }
17
+ let(:footprintable) { Footprintable.create!(:name => 'a footprinting model') }
18
+ let(:footprintable2) { Footprintable.create!(:name => 'a 2nd footprinting model') }
19
+
20
+ it "should be leave footprints" do
21
+ expect(footprintable.leave_footprints(user)).must_equal true
22
+ end
23
+
24
+ it "足跡の数が増えていること" do
25
+ expect(footprintable.footprint_count).must_equal 0
26
+ footprintable.leave_footprints user
27
+ expect(footprintable.footprint_count).must_equal 1
28
+ end
29
+
30
+ it "10回アクセスしたら10になること" do
31
+ expect(footprintable.footprint_count).must_equal 0
32
+ 10.times { footprintable.leave_footprints user }
33
+ expect(footprintable.footprint_count).must_equal 10
34
+ end
35
+
36
+ it "複数人でアクセスしたら合計されること" do
37
+ expect(footprintable.footprint_count).must_equal 0
38
+ 5.times { footprintable.leave_footprints user }
39
+ 5.times { footprintable.leave_footprints user2 }
40
+ expect(footprintable.footprint_count).must_equal 10
41
+ end
42
+
43
+ describe "期間指定をする" do
44
+ before do
45
+ (1..30).each do |day|
46
+ Timecop.travel(Time.parse("2013-09-#{day}")) do
47
+ 5.times { footprintable.leave_footprints user }
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "1週間の場合" do
53
+ it "35の足跡があること" do
54
+ Timecop.travel(Time.parse("2013-09-30 10:00:00")) do
55
+ expect(footprintable.footprint_count_between(1.week.ago..Time.now)).must_equal 35
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "1ヶ月の場合" do
61
+ it "150の足跡があること" do
62
+ Timecop.travel(Time.parse("2013-09-30 10:00:00")) do
63
+ expect(footprintable.footprint_count_between(1.month.ago..Time.now)).must_equal 150
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "アクセスランキングを作成" do
71
+ let(:user) { User.create!(:name => 'i can footprint!') }
72
+
73
+ describe "件数と期間を制限" do
74
+ before do
75
+ (1..30).each do |index|
76
+ Timecop.travel(Time.parse("2013-09-#{index}")) do
77
+ footprintable = Footprintable.create!(:name => "Footprintable#{index}")
78
+ index.times { footprintable.leave_footprints user }
79
+ end
80
+ end
81
+ end
82
+ subject do
83
+ month = Time.new(2013, 9, 1)
84
+ Footprintable.access_ranking(month.beginning_of_month...1.week.since(month), 5)
85
+ end
86
+
87
+ it 'アクセスランキングが取得できること' do
88
+ expect(subject).must_equal ({ 7 => 7, 6 => 6, 5 => 5, 4 => 4, 3 => 3 })
89
+ end
90
+
91
+ it '5件取得できること' do
92
+ expect(subject.count).must_equal 5
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,23 +1,22 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ require 'test_helper'
3
2
  require 'acts_as_footprintable/footprinter'
4
3
 
5
4
  describe ActsAsFootprintable::Footprinter do
6
5
 
7
6
  it "should not be a footprinter" do
8
- expect(NotUser).not_to be_footprinter
7
+ expect(NotUser).wont_be :footprinter?
9
8
  end
10
9
 
11
10
  it "should be a footprinter" do
12
- expect(User).to be_footprinter
11
+ expect(User).must_be :footprinter?
13
12
  end
14
13
 
15
14
  describe "ユーザーのアクセス履歴を" do
16
- let!(:user_1) { User.create!(:name => "user_1") }
15
+ let(:user_1) { User.create!(name: "user_1") }
17
16
  before do
18
17
  (1..5).each do |index|
19
- footprintable = Footprintable.create!(:name => "footprintable#{index}")
20
- second_footprintable = SecondFootprintable.create!(:name => "second_footprintable#{index}")
18
+ footprintable = Footprintable.create!(name: "footprintable#{index}")
19
+ second_footprintable = SecondFootprintable.create!(name: "second_footprintable#{index}")
21
20
  3.times do
22
21
  footprintable.leave_footprints user_1
23
22
  second_footprintable.leave_footprints user_1
@@ -25,38 +24,38 @@ describe ActsAsFootprintable::Footprinter do
25
24
  end
26
25
  end
27
26
 
28
- context "対象のモデル毎に" do
27
+ describe "対象のモデル毎に" do
29
28
  it "取得できること" do
30
- 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).count).must_equal 5
30
+ expect(user_1.access_histories_for(Footprintable).map { |footprint| footprint.footprintable.name }).must_equal (1..5).to_a.reverse.map { |index| "footprintable#{index}" }
32
31
  end
33
32
 
34
33
  it "件数を絞り込めること" do
35
- 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).count).must_equal 3
35
+ expect(user_1.access_histories_for(Footprintable, 3).map { |footprint| footprint.footprintable.name }).must_equal (3..5).to_a.reverse.map { |index| "footprintable#{index}" }
37
36
  end
38
37
  end
39
38
 
40
- context "全てのモデルを通じて" do
39
+ describe "全てのモデルを通じて" do
41
40
  it "取得できること" do
42
- expect(user_1.access_histories.count).to eq 10
41
+ expect(user_1.access_histories.count).must_equal 10
43
42
  footprintable_names = (1..5).to_a.reverse.inject([]) do |results, index|
44
43
  results.push "second_footprintable#{index}"
45
44
  results.push "footprintable#{index}"
46
45
  results
47
46
  end
48
- expect(user_1.access_histories.map{|footprint| footprint.footprintable.name}).to eq footprintable_names
47
+ expect(user_1.access_histories.map { |footprint| footprint.footprintable.name }).must_equal footprintable_names
49
48
  end
50
49
 
51
50
  it "件数を絞り込める事" do
52
- expect(user_1.access_histories(3).count).to eq 3
51
+ expect(user_1.access_histories(3).count).must_equal 3
53
52
  end
54
53
  end
55
54
 
56
- context 'アクセス履歴のないユーザーの場合' do
57
- let!(:user_2) { User.create!(:name => "user_2") }
55
+ describe 'アクセス履歴のないユーザーの場合' do
56
+ let(:user_2) { User.create!(:name => "user_2") }
58
57
  it '件数が0件であること' do
59
- expect(user_2.access_histories_for(Footprintable).count).to eq 0
58
+ expect(user_2.access_histories_for(Footprintable).count).must_equal 0
60
59
  end
61
60
  end
62
61
  end
File without changes
File without changes
File without changes
@@ -1,4 +1,13 @@
1
- # coding: utf-8
1
+ require 'minitest/autorun'
2
+ require 'active_record'
3
+
4
+ require 'database_cleaner/active_record'
5
+ require "acts_as_footprintable"
6
+ require 'timecop'
7
+
8
+ Dir["#{Dir.pwd}/test/internal/app/models/*.rb"].each(&method(:require))
9
+
10
+ ActiveRecord::Base.establish_connection('adapter' => 'sqlite3', 'database' => ':memory:')
2
11
  ActiveRecord::Schema.define do
3
12
  create_table :footprints, :force => true do |t|
4
13
  t.references :footprintable, :polymorphic => true
@@ -29,3 +38,16 @@ ActiveRecord::Schema.define do
29
38
  t.string :name
30
39
  end
31
40
  end
41
+
42
+ DatabaseCleaner.strategy = :transaction
43
+
44
+ class Minitest::Spec
45
+
46
+ before :each do
47
+ DatabaseCleaner.start
48
+ end
49
+
50
+ after :each do
51
+ DatabaseCleaner.clean
52
+ end
53
+ end
metadata CHANGED
@@ -1,83 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_footprintable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyoaki Oko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '13.0'
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.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 3.0.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 3.0.0
55
- - !ruby/object:Gem::Dependency
56
- name: pg
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
26
+ version: '13.0'
69
27
  - !ruby/object:Gem::Dependency
70
28
  name: timecop
71
29
  requirement: !ruby/object:Gem::Requirement
72
30
  requirements:
73
- - - ">="
31
+ - - "~>"
74
32
  - !ruby/object:Gem::Version
75
33
  version: '0'
76
34
  type: :development
77
35
  prerelease: false
78
36
  version_requirements: !ruby/object:Gem::Requirement
79
37
  requirements:
80
- - - ">="
38
+ - - "~>"
81
39
  - !ruby/object:Gem::Version
82
40
  version: '0'
83
41
  - !ruby/object:Gem::Dependency
@@ -86,28 +44,35 @@ dependencies:
86
44
  requirements:
87
45
  - - "~>"
88
46
  - !ruby/object:Gem::Version
89
- version: 1.0.1
47
+ version: '2.0'
90
48
  type: :development
91
49
  prerelease: false
92
50
  version_requirements: !ruby/object:Gem::Requirement
93
51
  requirements:
94
52
  - - "~>"
95
53
  - !ruby/object:Gem::Version
96
- version: 1.0.1
54
+ version: '2.0'
97
55
  description: Rails gem to allowing records to leave footprints
98
56
  email: chariderpato@gmail.com
99
57
  executables: []
100
58
  extensions: []
101
59
  extra_rdoc_files: []
102
60
  files:
61
+ - ".github/workflows/gem-push.yml"
62
+ - ".github/workflows/test.yml"
103
63
  - ".gitignore"
104
- - ".rspec"
105
- - ".travis.yml"
106
64
  - Gemfile
107
65
  - LICENSE.txt
108
66
  - README.md
109
67
  - Rakefile
110
68
  - acts_as_footprintable.gemspec
69
+ - config.ru
70
+ - gemfiles/rails_5.0.gemfile
71
+ - gemfiles/rails_5.1.gemfile
72
+ - gemfiles/rails_5.2.gemfile
73
+ - gemfiles/rails_6.0.gemfile
74
+ - gemfiles/rails_6.1.gemfile
75
+ - gemfiles/rails_7.0.gemfile
111
76
  - lib/acts_as_footprintable.rb
112
77
  - lib/acts_as_footprintable/extenders/footprintable.rb
113
78
  - lib/acts_as_footprintable/extenders/footprinter.rb
@@ -117,17 +82,14 @@ files:
117
82
  - lib/acts_as_footprintable/version.rb
118
83
  - lib/generators/acts_as_footprintable/migration/migration_generator.rb
119
84
  - lib/generators/acts_as_footprintable/migration/templates/active_record/migration.rb
120
- - spec/footprintable_spec.rb
121
- - spec/footprinter_spec.rb
122
- - spec/internal/app/models/footprintable.rb
123
- - spec/internal/app/models/not_footprintable.rb
124
- - spec/internal/app/models/not_user.rb
125
- - spec/internal/app/models/second_footprintable.rb
126
- - spec/internal/app/models/user.rb
127
- - spec/internal/config/database.yml
128
- - spec/internal/db/schema.rb
129
- - spec/internal/log/.gitignore
130
- - spec/spec_helper.rb
85
+ - test/footprintable_test.rb
86
+ - test/footprinter_test.rb
87
+ - test/internal/app/models/footprintable.rb
88
+ - test/internal/app/models/not_footprintable.rb
89
+ - test/internal/app/models/not_user.rb
90
+ - test/internal/app/models/second_footprintable.rb
91
+ - test/internal/app/models/user.rb
92
+ - test/test_helper.rb
131
93
  homepage: https://github.com/patorash/acts_as_footprintable
132
94
  licenses:
133
95
  - MIT
@@ -147,20 +109,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
109
  - !ruby/object:Gem::Version
148
110
  version: '0'
149
111
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.5.2
112
+ rubygems_version: 3.0.3.1
152
113
  signing_key:
153
114
  specification_version: 4
154
115
  summary: Rails gem to allowing records to leave footprints
155
116
  test_files:
156
- - spec/footprintable_spec.rb
157
- - spec/footprinter_spec.rb
158
- - spec/internal/app/models/footprintable.rb
159
- - spec/internal/app/models/not_footprintable.rb
160
- - spec/internal/app/models/not_user.rb
161
- - spec/internal/app/models/second_footprintable.rb
162
- - spec/internal/app/models/user.rb
163
- - spec/internal/config/database.yml
164
- - spec/internal/db/schema.rb
165
- - spec/internal/log/.gitignore
166
- - spec/spec_helper.rb
117
+ - test/footprintable_test.rb
118
+ - test/footprinter_test.rb
119
+ - test/internal/app/models/footprintable.rb
120
+ - test/internal/app/models/not_footprintable.rb
121
+ - test/internal/app/models/not_user.rb
122
+ - test/internal/app/models/second_footprintable.rb
123
+ - test/internal/app/models/user.rb
124
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --drb --colour --format documentation
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4.0
4
- - 2.3.3
5
- - 2.2.6
6
- - 2.1.10
7
- env:
8
- - "RAILS_VERSION=5.0.0"
9
- - "RAILS_VERSION=4.2.0"
10
- - "RAILS_VERSION=4.1.0"
11
- - "RAILS_VERSION=4.0.0"
12
- - "RAILS_VERSION=3.2.0"
13
- branches:
14
- only:
15
- - master
16
- - travis
@@ -1,98 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe ActsAsFootprintable::Footprintable do
5
-
6
- it "should not be a footprintable" do
7
- expect(NotFootprintable).not_to be_footprintable
8
- end
9
-
10
- it "should be a footprintable" do
11
- expect(Footprintable).to be_footprintable
12
- end
13
-
14
- describe 'leave footprints by footprinter' do
15
-
16
- before do
17
- @user = User.create!(:name => 'i can footprint!')
18
- @user2 = User.create!(:name => 'a new person')
19
-
20
- @footprintable = Footprintable.create!(:name => 'a footprinting model')
21
- @footprintable2 = Footprintable.create!(:name => 'a 2nd footprinting model')
22
- end
23
-
24
- it "should be leave footprints" do
25
- expect(@footprintable.leave_footprints(@user)).to be_truthy
26
- end
27
-
28
- it "足跡の数が増えていること" do
29
- expect {
30
- @footprintable.leave_footprints @user
31
- }.to change{ @footprintable.footprint_count }.from(0).to(1)
32
- end
33
-
34
- it "10回アクセスしたら10になること" do
35
- expect {
36
- 10.times { @footprintable.leave_footprints @user }
37
- }.to change{ @footprintable.footprint_count }.from(0).to(10)
38
- end
39
-
40
- it "複数人でアクセスしたら合計されること" do
41
- expect {
42
- 5.times { @footprintable.leave_footprints @user }
43
- 5.times { @footprintable.leave_footprints @user2 }
44
- }.to change{ @footprintable.footprint_count }.from(0).to(10)
45
- end
46
-
47
- describe "期間指定をする" do
48
- before do
49
- (1..30).each do |day|
50
- Timecop.travel(Time.parse("2013/9/#{day}")) do
51
- 5.times {@footprintable.leave_footprints @user}
52
- end
53
- end
54
- end
55
-
56
- context "1週間の場合" do
57
- it "35の足跡があること" do
58
- Timecop.travel(Time.parse("2013/9/30 10:00:00")) do
59
- expect(@footprintable.footprint_count_between(1.week.ago..Time.now)).to eq 35
60
- end
61
- end
62
- end
63
-
64
- context "1ヶ月の場合" do
65
- it "150の足跡があること" do
66
- Timecop.travel(Time.parse("2013/9/30 10:00:00")) do
67
- expect(@footprintable.footprint_count_between(1.month.ago..Time.now)).to eq 150
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- describe "アクセスランキングを作成" do
75
- before do
76
- @user = User.create!(:name => 'i can footprint!')
77
- end
78
-
79
- context "件数と期間を制限" do
80
- before do
81
- (1..30).each do |index|
82
- Timecop.travel(Time.parse("2013/9/#{index}")) do
83
- footprintable = Footprintable.create!(:name => "Footprintable#{index}")
84
- index.times {footprintable.leave_footprints @user}
85
- end
86
- end
87
- end
88
- subject do
89
- month = Time.new(2013,9,1)
90
- Footprintable.access_ranking(month.beginning_of_month...1.week.since(month), 5)
91
- end
92
- it { is_expected.to eq ({7 => 7, 6 => 6, 5 => 5, 4 => 4, 3 => 3 }) }
93
- it '5件取得できること' do
94
- expect(subject.count).to eq 5
95
- end
96
- end
97
- end
98
- end
@@ -1,5 +0,0 @@
1
- test:
2
- adapter: postgresql
3
- encoding: unicode
4
- database: acts_as_footprintable
5
- min_messages: WARNING
@@ -1 +0,0 @@
1
- *.log
data/spec/spec_helper.rb DELETED
@@ -1,23 +0,0 @@
1
- ## coding: utf-8
2
- require 'rubygems'
3
- require 'bundler/setup'
4
- require 'combustion'
5
- require 'database_cleaner'
6
- require 'timecop'
7
-
8
- Combustion.initialize! :active_record
9
-
10
- RSpec.configure do |config|
11
- config.run_all_when_everything_filtered = true
12
- config.filter_run :focus
13
-
14
- config.before :suite do
15
- DatabaseCleaner.strategy = :truncation
16
- end
17
- config.before :each do
18
- DatabaseCleaner.start
19
- end
20
- config.after :each do
21
- DatabaseCleaner.clean
22
- end
23
- end