catptcha 0.1.4 → 0.1.5
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.
- data/README.markdown +12 -2
- data/catptcha.gemspec +1 -0
- data/lib/catptcha.rb +15 -3
- data/lib/catptcha/photo_group.rb +9 -0
- data/test/catptcha_seed_test.rb +3 -3
- data/test/test_helper.rb +1 -1
- metadata +20 -6
data/README.markdown
CHANGED
@@ -37,7 +37,7 @@ Run the tests.
|
|
37
37
|
|
38
38
|
Include the partial in your form contents.
|
39
39
|
|
40
|
-
render :inline => Catptcha.puzzle_tags
|
40
|
+
render :inline => Catptcha.puzzle_tags :catptcha_guess
|
41
41
|
|
42
42
|
Check the result in your controller.
|
43
43
|
|
@@ -47,9 +47,19 @@ Check the result in your controller.
|
|
47
47
|
# failed
|
48
48
|
end
|
49
49
|
|
50
|
+
There are also tools for implementing an admin/review UI:
|
51
|
+
|
52
|
+
# Get all kitten images, paginated (uses will_paginate)
|
53
|
+
Catptcha.paginate_kitten_images(page)
|
54
|
+
|
55
|
+
# Get all not-a-kitten images, paginated (uses will_paginate)
|
56
|
+
Catptcha.paginate_not_kitten_images(page)
|
57
|
+
|
58
|
+
# remove an image given the key
|
59
|
+
Catptcha.remove_image(key)
|
60
|
+
|
50
61
|
## TODO and Known Bugs
|
51
62
|
|
52
|
-
* lacks a review step for seeded photos
|
53
63
|
* lacks the ability to store or upload photos to external storage
|
54
64
|
* current implementation is closely tied to ActiveRecord and Flickr
|
55
65
|
|
data/catptcha.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
EOD
|
11
11
|
s.add_dependency "commonthread-flickr_fu", "0.3.0"
|
12
12
|
s.add_dependency "activerecord", "~>2.3"
|
13
|
+
s.add_dependency "will_paginate"
|
13
14
|
s.add_development_dependency "rr"
|
14
15
|
s.authors = ['Zack Hobson']
|
15
16
|
s.files = `git ls-files`.split("\n")
|
data/lib/catptcha.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Catptcha
|
2
|
-
VERSION = '0.1.
|
2
|
+
VERSION = '0.1.5'
|
3
3
|
|
4
4
|
class << self
|
5
5
|
# Get a list of 3 kitten photos
|
@@ -16,6 +16,18 @@ module Catptcha
|
|
16
16
|
(kittens + not_kittens).sort_by {rand}
|
17
17
|
end
|
18
18
|
|
19
|
+
def paginate_kittens(page)
|
20
|
+
PhotoGroup.kittens.paginate(page)
|
21
|
+
end
|
22
|
+
|
23
|
+
def paginate_not_kittens(page)
|
24
|
+
PhotoGroup.not_kittens.paginate(page)
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove_image(key)
|
28
|
+
Photo.first(:conditions => {:key => key}).try(:destroy)
|
29
|
+
end
|
30
|
+
|
19
31
|
def puzzle_js
|
20
32
|
return <<-EOJS
|
21
33
|
function catptcha_click(e) {
|
@@ -27,12 +39,12 @@ module Catptcha
|
|
27
39
|
}
|
28
40
|
EOJS
|
29
41
|
end
|
30
|
-
def puzzle_tags
|
42
|
+
def puzzle_tags param_name='catptcha_guess'
|
31
43
|
tags = '<div class="catptcha" style="width:340px"><p>Click the 3 kitties!</p>'
|
32
44
|
puzzle.each do |photo|
|
33
45
|
tags << <<-EOT
|
34
46
|
<span class="catptcha_guess" style="float:left">
|
35
|
-
<input type="checkbox" id="catptcha_guess_#{photo.key}" name="
|
47
|
+
<input type="checkbox" id="catptcha_guess_#{photo.key}" name="#{ param_name }[]" value="#{ photo.key }" onclick="catptcha_click(this)" style="opacity:0.0;width:0px;"/>
|
36
48
|
<label for="catptcha_guess_#{photo.key }" style="margin:2px">
|
37
49
|
<img src="#{ photo.url }" title="#{photo.attribution}" alt="#{photo.attribution}" style="padding: 2px" />
|
38
50
|
</label>
|
data/lib/catptcha/photo_group.rb
CHANGED
@@ -15,6 +15,15 @@ class Catptcha::PhotoGroup < ActiveRecord::Base
|
|
15
15
|
sum(:photos_count)
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.paginate(page)
|
19
|
+
Catptcha::Photo.paginate(
|
20
|
+
:conditions => {:photo_group_id => all.map(&:id)},
|
21
|
+
:order => 'photo_group_id',
|
22
|
+
:page => page,
|
23
|
+
:per_page => 110
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
18
27
|
def self.random count
|
19
28
|
Catptcha::Photo.all(
|
20
29
|
:conditions => ['photo_group_id in (?)', all.map(&:id)],
|
data/test/catptcha_seed_test.rb
CHANGED
@@ -9,16 +9,16 @@ class CatptchaSeedTest < Test::Unit::TestCase
|
|
9
9
|
def test_seed_with_no_photos
|
10
10
|
stub(Catptcha::Seed).flickr { build_flickr_stub [] }
|
11
11
|
Catptcha::Seed.update :silent
|
12
|
-
assert_equal
|
12
|
+
assert_equal 6, Catptcha::PhotoGroup.count
|
13
13
|
assert_equal 0, Catptcha::Photo.count
|
14
14
|
# doesn't recreate groups
|
15
15
|
Catptcha::Seed.update :silent
|
16
|
-
assert_equal
|
16
|
+
assert_equal 6, Catptcha::PhotoGroup.count
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_seed_with_photos
|
20
20
|
stub(Catptcha::Seed).flickr { build_flickr_stub { [ build_flickr_photo_stub ] } }
|
21
21
|
Catptcha::Seed.update :silent
|
22
|
-
assert_equal
|
22
|
+
assert_equal 6, Catptcha::Photo.count
|
23
23
|
end
|
24
24
|
end
|
data/test/test_helper.rb
CHANGED
@@ -12,7 +12,7 @@ class Test::Unit::TestCase
|
|
12
12
|
@index += 1
|
13
13
|
Object.new.tap do |photo|
|
14
14
|
stub(photo).url { "http://#{@index}" }
|
15
|
-
stub(photo).license { stub(Object.new).
|
15
|
+
stub(photo).license { stub(Object.new).name {'http://license.info'} }
|
16
16
|
stub(photo).owner { "abc" }
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zack Hobson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
|
-
name:
|
53
|
+
name: will_paginate
|
54
54
|
prerelease: false
|
55
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
@@ -61,8 +61,22 @@ dependencies:
|
|
61
61
|
segments:
|
62
62
|
- 0
|
63
63
|
version: "0"
|
64
|
-
type: :
|
64
|
+
type: :runtime
|
65
65
|
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rr
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
66
80
|
description: " Choose the kitten!\n"
|
67
81
|
email:
|
68
82
|
executables: []
|