picky-client 0.9.1 → 0.9.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.
@@ -67,9 +67,14 @@ module Picky
67
67
  # have populated the results.
68
68
  #
69
69
  def entries limit = 20
70
- entries = []
71
- allocations.each { |allocation| allocation[5].each { |id| break if entries.size > limit; entries << id } }
72
- entries
70
+ if block_given?
71
+ i = 0
72
+ allocations.each { |allocation| allocation[5].collect! { |ar_or_rendered| break if i >= limit; i = i + 1; yield ar_or_rendered } }
73
+ else
74
+ entries = []
75
+ allocations.each { |allocation| allocation[5].each { |ar_or_rendered| break if entries.size >= limit; entries << ar_or_rendered } }
76
+ entries
77
+ end
73
78
  end
74
79
 
75
80
  # The ids need to come in the order which the ids were returned by the ids method.
@@ -5,15 +5,15 @@ var PickyI18n = { };
5
5
  // Set the correct locale for all js code.
6
6
  //
7
7
  $(function() {
8
- PickyI18n.locale = $('html').attr('lang') || 'en';
8
+ PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
9
9
  });
10
10
 
11
11
  var dictionary = {
12
12
  common:{
13
- join: {de:'und',fr:'et',it:'e',en:'and',ch:'und'},
14
- 'with': {de:'mit',fr:'avec',it:'con',en:'with',ch:'mit'},
15
- of: {de:'von',fr:'de',it:'di',en:'of',ch:'vo'},
16
- to: {de:'bis',fr:'à',it:'alla',en:'to',ch:'bis'}
13
+ join: { de: 'und', fr: 'et', it: 'e', en: 'and', ch: 'und' },
14
+ 'with': { de: 'mit', fr: 'avec',it: 'con', en: 'with', ch: 'mit' },
15
+ of: { de: 'von', fr: 'de', it: 'di', en: 'of', ch: 'vo' },
16
+ to: { de: 'bis', fr: 'à', it: 'alla', en: 'to', ch: 'bis' }
17
17
  },
18
18
  results:{
19
19
  addination:{
@@ -4,15 +4,78 @@ describe Picky::Convenience do
4
4
 
5
5
  before(:each) do
6
6
  @convenience = {
7
- :allocations => [[nil, nil, nil, nil, [1,2,3,4,5,6,7,8]],
8
- [nil, nil, nil, nil, [9,10,11,12,13,14,15,16]],
9
- [nil, nil, nil, nil, [17,18,19,20,21,22,23]]],
7
+ :allocations => [[nil, nil, nil, nil, [1,2,3,4,5,6,7,8], [1,2,3,4,5,6,7,8]],
8
+ [nil, nil, nil, nil, [9,10,11,12,13,14,15,16], [9,10,11,12,13,14,15,16]],
9
+ [nil, nil, nil, nil, [17,18,19,20,21,22,23], [17,18,19,20,21,22,23]]],
10
10
  :offset => 123,
11
11
  :total => 12345,
12
12
  :duration => 0.12345
13
13
  }.extend Picky::Convenience
14
14
  end
15
15
 
16
+ describe "entries" do
17
+ context "default" do
18
+ context "without block" do
19
+ it "returns 20 values" do
20
+ @convenience.entries.should == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
21
+ end
22
+ end
23
+ context "with block" do
24
+ it "yields 20 times, each time a different element" do
25
+ amount = {}
26
+ @convenience.entries do |entry|
27
+ amount[entry] = true
28
+ end
29
+ amount.size.should == 20
30
+ end
31
+ it "replaces all entries" do
32
+ @convenience.entries do |entry|
33
+ entry + 1
34
+ end
35
+ @convenience.entries.should == (2..21).to_a
36
+ end
37
+ end
38
+ end
39
+ context "with value" do
40
+ context "without block" do
41
+ it "returns 0 entries" do
42
+ @convenience.entries(0).should == []
43
+ end
44
+ it "returns 1 entry" do
45
+ @convenience.entries(1).should == [1]
46
+ end
47
+ it "handles more wished entries than it has" do
48
+ @convenience.entries(30).should == (1..23).to_a
49
+ end
50
+ end
51
+ context "with block" do
52
+ it "yields never" do
53
+ @convenience.entries(0) do |entry|
54
+ entry.should == :gnorf
55
+ end
56
+ end
57
+ it "yields once" do
58
+ @convenience.entries(1) do |entry|
59
+ entry.should == 1
60
+ end
61
+ end
62
+ it "yields the amount of entries it has even if more are wished" do
63
+ amount = {}
64
+ @convenience.entries(30) do |entry|
65
+ amount[entry] = true
66
+ end
67
+ amount.size.should == 23
68
+ end
69
+ it "replaces all entries" do
70
+ @convenience.entries(30) do |entry|
71
+ entry + 1
72
+ end
73
+ @convenience.entries(30).should == (2..24).to_a
74
+ end
75
+ end
76
+ end
77
+ end
78
+
16
79
  describe "populate_with" do
17
80
  before(:each) do
18
81
  @results = {
@@ -40,11 +103,11 @@ describe Picky::Convenience do
40
103
  end
41
104
  it "should populate correctly even without a block" do
42
105
  @results.populate_with ARClass
43
- @results.entries.should == (1..21).map { |id| ARClass.new(id) }
106
+ @results.entries.should == (1..20).map { |id| ARClass.new(id) }
44
107
  end
45
108
  it "should populate correctly with a render block" do
46
109
  @results.populate_with(ARClass) { |ar_instance| ar_instance.id.to_s }
47
- @results.entries.should == (1..21).map { |id| id.to_s } # "rendering" using to_s
110
+ @results.entries.should == (1..20).map { |id| id.to_s } # "rendering" using to_s
48
111
  end
49
112
  end
50
113
 
@@ -63,7 +126,7 @@ describe Picky::Convenience do
63
126
  it 'should populate with the entries' do
64
127
  new_ids = (11..31).to_a # +10
65
128
  @results.replace_ids_with new_ids
66
- @results.entries.should == (11..31).to_a
129
+ @results.entries.should == (11..30).to_a
67
130
  end
68
131
  end
69
132
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 1
9
- version: 0.9.1
8
+ - 2
9
+ version: 0.9.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-27 00:00:00 +02:00
17
+ date: 2010-10-29 00:00:00 +02:00
18
18
  default_executable: picky-client
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency