acts_as_footprintable 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/acts_as_footprintable/footprinter.rb +2 -0
- data/lib/acts_as_footprintable/version.rb +1 -1
- data/spec/footprinter_spec.rb +17 -10
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0836653de448c2d10bb14e4e2d3bd6f0dc584ce3'
|
|
4
|
+
data.tar.gz: f8a02be5d569784ff93fe363774e1e3de4fd8900
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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(',')})"
|
data/spec/footprinter_spec.rb
CHANGED
|
@@ -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
|
|
23
|
-
second_footprintable.leave_footprints
|
|
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(
|
|
31
|
-
expect(
|
|
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(
|
|
36
|
-
expect(
|
|
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(
|
|
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(
|
|
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(
|
|
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.
|
|
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-
|
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|