catptcha 0.1.1 → 0.1.2

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.
@@ -3,6 +3,7 @@ class <%= class_name %> < ActiveRecord::Migration
3
3
  create_table :catptcha_photos do |t|
4
4
  t.belongs_to :photo_group
5
5
  t.string :key
6
+ t.string :attribution
6
7
  t.string :url
7
8
  end
8
9
  add_index :catptcha_photos, :photo_group_id
data/lib/catptcha.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Catptcha
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
 
4
4
  class << self
5
5
  # Get a list of 3 kitten photos
@@ -20,7 +20,7 @@ module Catptcha
20
20
  return <<-EOJS
21
21
  function catptcha_click(e) {
22
22
  if (e.checked) {
23
- e.parentNode.getElementsByTagName('img')[0].setAttribute("style","border: 2px inset black;");
23
+ e.parentNode.getElementsByTagName('img')[0].setAttribute("style","border: 2px solid black;");
24
24
  } else {
25
25
  e.parentNode.getElementsByTagName('img')[0].setAttribute("style", "padding: 2px");
26
26
  }
@@ -28,13 +28,13 @@ module Catptcha
28
28
  EOJS
29
29
  end
30
30
  def puzzle_tags
31
- tags = '<div class="catptcha" style="width:340px"><p>Click the 3 kittens!</p>'
31
+ tags = '<div class="catptcha" style="width:340px"><p>Click the 3 kitties!</p>'
32
32
  puzzle.each do |photo|
33
33
  tags << <<-EOT
34
34
  <span class="catptcha_guess" style="float:left">
35
35
  <input type="checkbox" id="catptcha_guess_#{photo.key}" name="catptcha_guess[]" value="#{ photo.key }" onclick="catptcha_click(this)" style="opacity:0.0;width:0px;"/>
36
36
  <label for="catptcha_guess_#{photo.key }" style="margin:2px">
37
- <img src="#{ photo.url }" style="padding: 2px" />
37
+ <img src="#{ photo.url }" title="#{photo.attribution}" alt="#{photo.attribution}" style="padding: 2px" />
38
38
  </label>
39
39
  </span>
40
40
  EOT
data/lib/catptcha/seed.rb CHANGED
@@ -15,6 +15,11 @@ module Catptcha::Seed
15
15
  @flickr ||= Flickr.new(Rails.root.join("config/flickr.yml").to_s)
16
16
  end
17
17
 
18
+ def reset
19
+ Catptcha::Photo.delete_all
20
+ Catptcha::PhotoGroup.delete_all
21
+ end
22
+
18
23
  def update silent=false
19
24
  SEED_GROUP_KITTENS.each do |name, id|
20
25
  Catptcha::PhotoGroup.create(:name => name.to_s, :flickr_group_id => id, :kittens => true)
@@ -33,6 +38,7 @@ module Catptcha::Seed
33
38
  def update_photos group
34
39
  params = {
35
40
  :group_id => group.flickr_group_id, :safe_search => 1, :content_type => 1,
41
+ :license => '4,6', #Attribution/NoDerivs
36
42
  :per_page => 500, :page => 1
37
43
  }
38
44
  params[:min_upload_date] = group.photos_updated_at if group.photos_updated_at
@@ -42,7 +48,9 @@ module Catptcha::Seed
42
48
  loop do
43
49
  result = flickr.photos.search(params)
44
50
  result.each do |photo|
45
- group.photos.create(:url => photo.url(:square))
51
+ owner = flickr.people.find_by_id(photo.owner)
52
+ attribution = owner ? "© #{owner.realname || owner.username} (CC #{photo.license.name})" : ''
53
+ group.photos.create(:url => photo.url(:square), :attribution => attribution)
46
54
  photo_count += 1
47
55
  end
48
56
  if total_pages.nil?
@@ -3,6 +3,11 @@ namespace :catptcha do
3
3
  task :seed => :environment do
4
4
  Catptcha::Seed.update
5
5
  end
6
+
7
+ desc 'clear all captcha groups and images'
8
+ task :reset => :environment do
9
+ Catptcha::Seed.reset
10
+ end
6
11
 
7
12
  desc 'run catptcha plugin tests'
8
13
  Rake::TestTask.new do |t|
@@ -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 3, Catptcha::PhotoGroup.count
12
+ assert_equal 4, 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 3, Catptcha::PhotoGroup.count
16
+ assert_equal 4, 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 3, Catptcha::Photo.count
22
+ assert_equal 4, Catptcha::Photo.count
23
23
  end
24
24
  end
@@ -12,11 +12,11 @@ class CatptchaTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_kittens
15
- assert Catptcha.check_guesses(Catptcha.kittens.map(&:key))
15
+ assert Catptcha.check_guess(Catptcha.kittens.map(&:key))
16
16
  end
17
17
 
18
18
  def test_not_kittens
19
- assert !Catptcha.check_guesses(Catptcha.not_kittens.map(&:key)[0,3])
19
+ assert !Catptcha.check_guess(Catptcha.not_kittens.map(&:key)[0,3])
20
20
  end
21
21
 
22
22
  def test_puzzle
data/test/test_helper.rb CHANGED
@@ -12,6 +12,8 @@ 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).url {'http://license.info'} }
16
+ stub(photo).owner { "abc" }
15
17
  end
16
18
  end
17
19
 
@@ -19,6 +21,10 @@ class Test::Unit::TestCase
19
21
  # for lazy evaluation pass the photos in a block instead
20
22
  def build_flickr_stub value=nil
21
23
  Object.new.tap do |flickr|
24
+ people = Object.new
25
+ stub(flickr).people { stub(people).find_by_id {
26
+ Object.new.tap {|result| stub(result).realname { 'bob' } }
27
+ }}
22
28
  photos = Object.new
23
29
  stub(flickr).photos { stub(photos).search {
24
30
  (value || yield).tap {|result| stub(result).pages { 1 } }
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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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 00:00:00 -07:00
18
+ date: 2012-05-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency