acts_as_footprintable 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5511b19bf736e594da831847c7e5680ed541f45
4
- data.tar.gz: 587ada66643a68366b0099661d9a3f420f373f76
3
+ metadata.gz: '0836653de448c2d10bb14e4e2d3bd6f0dc584ce3'
4
+ data.tar.gz: f8a02be5d569784ff93fe363774e1e3de4fd8900
5
5
  SHA512:
6
- metadata.gz: 1b3ee4db822262a0e47e15d49959b50552bb26b7c088163fb2006341e96fc62a5a897c2d48f2b5919eca9ca9eb7d2c070e05b34efd6ff0e7edaee0856c24e02c
7
- data.tar.gz: 266229cf82bb0245dd70a330a527cff8619ef19734fdf59b4f010eadc383eb18336b5e7bd6b68f076e0b6acc9751ae1ebd1bc41425cf248fb07d6edd0d9db063
6
+ metadata.gz: a3b349f2dafb4fb541669e2944c9737c774ca75ac380cd578ddab47db8fb489d3b2209a228a334ec655d5dab3453191e7dbf9cbf9db85975d1d58568fe61ba6d
7
+ data.tar.gz: e61673ab9a1e77f4881ee3dbe6719319eba203b3d4d5e7a8fe77767a7702eb1ff8b22b4c3fd8af430fa89062c4b159a66c16cf933bc997442d9bb874a69f9e35
@@ -41,6 +41,8 @@ module ActsAsFootprintable
41
41
  recent_footprints = target.group("#{table_name}.footprintable_id, #{table_name}.footprintable_type").
42
42
  select("#{table_name}.footprintable_id, #{table_name}.footprintable_type, MAX(#{table_name}.created_at) AS created_at")
43
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
+
44
46
  columns = recent_footprints_conditions.first.keys.map{|column| "#{table_name}.#{column}" }.join(',')
45
47
  values = recent_footprints_conditions.map { |row|
46
48
  "(#{row.values.map{|value| ActiveRecord::Base::sanitize(value)}.join(',')})"
@@ -1,4 +1,4 @@
1
1
  # coding: utf-8
2
2
  module ActsAsFootprintable
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
@@ -13,43 +13,50 @@ describe ActsAsFootprintable::Footprinter do
13
13
  end
14
14
 
15
15
  describe "ユーザーのアクセス履歴を" do
16
+ let!(:user_1) { User.create!(:name => "user_1") }
16
17
  before do
17
- @user = User.create!(:name => "user")
18
18
  (1..5).each do |index|
19
19
  footprintable = Footprintable.create!(:name => "footprintable#{index}")
20
20
  second_footprintable = SecondFootprintable.create!(:name => "second_footprintable#{index}")
21
21
  3.times do
22
- footprintable.leave_footprints @user
23
- second_footprintable.leave_footprints @user
22
+ footprintable.leave_footprints user_1
23
+ second_footprintable.leave_footprints user_1
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
28
  context "対象のモデル毎に" do
29
29
  it "取得できること" do
30
- expect(@user.access_histories_for(Footprintable).count).to eq 5
31
- expect(@user.access_histories_for(Footprintable).map{|footprint| footprint.footprintable.name}).to eq (1..5).to_a.reverse.map{|index| "footprintable#{index}"}
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}"}
32
32
  end
33
33
 
34
34
  it "件数を絞り込めること" do
35
- expect(@user.access_histories_for(Footprintable, 3).count).to eq 3
36
- expect(@user.access_histories_for(Footprintable, 3).map{|footprint| footprint.footprintable.name}).to eq (3..5).to_a.reverse.map{|index| "footprintable#{index}"}
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}"}
37
37
  end
38
38
  end
39
39
 
40
40
  context "全てのモデルを通じて" do
41
41
  it "取得できること" do
42
- expect(@user.access_histories.count).to eq 10
42
+ expect(user_1.access_histories.count).to eq 10
43
43
  footprintable_names = (1..5).to_a.reverse.inject([]) do |results, index|
44
44
  results.push "second_footprintable#{index}"
45
45
  results.push "footprintable#{index}"
46
46
  results
47
47
  end
48
- expect(@user.access_histories.map{|footprint| footprint.footprintable.name}).to eq footprintable_names
48
+ expect(user_1.access_histories.map{|footprint| footprint.footprintable.name}).to eq footprintable_names
49
49
  end
50
50
 
51
51
  it "件数を絞り込める事" do
52
- expect(@user.access_histories(3).count).to eq 3
52
+ expect(user_1.access_histories(3).count).to eq 3
53
+ end
54
+ end
55
+
56
+ context 'アクセス履歴のないユーザーの場合' do
57
+ let!(:user_2) { User.create!(:name => "user_2") }
58
+ it '件数が0件であること' do
59
+ expect(user_2.access_histories_for(Footprintable).count).to eq 0
53
60
  end
54
61
  end
55
62
  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.3.0
4
+ version: 0.3.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-10 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler