lolita 3.0.7 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/GUIDELINE +4 -0
  2. data/README.rdoc +50 -0
  3. data/VERSION +1 -1
  4. data/app/controllers/lolita/rest_controller.rb +27 -11
  5. data/app/helpers/components/lolita/configuration/list_component.rb +11 -0
  6. data/app/helpers/lolita_helper.rb +1 -1
  7. data/app/views/components/lolita/configuration/field/_display.html.erb +9 -0
  8. data/app/views/components/lolita/configuration/field/_label.html.erb +1 -0
  9. data/app/views/components/lolita/{field → configuration/field}/_object.html.erb +0 -0
  10. data/app/views/components/lolita/configuration/field/array/_display.html.erb +5 -0
  11. data/app/views/components/lolita/configuration/field/array/habtm/_display.html.erb +26 -0
  12. data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +5 -0
  13. data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +1 -0
  14. data/app/views/components/lolita/{field/_boolean.html.erb → configuration/field/boolean/_display.html.erb} +0 -0
  15. data/app/views/components/lolita/configuration/field/date/_display.html.erb +1 -0
  16. data/app/views/components/lolita/{field/_string.html.erb → configuration/field/float/_display.html.erb} +0 -0
  17. data/app/views/components/lolita/configuration/field/integer/_display.html.erb +1 -0
  18. data/app/views/components/lolita/configuration/field/string/_display.html.erb +5 -0
  19. data/app/views/components/lolita/{field/_disabled.html.erb → configuration/field/string/disabled/_display.html.erb} +0 -0
  20. data/app/views/components/lolita/{field/_password.html.erb → configuration/field/string/password/_display.html.erb} +0 -0
  21. data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +34 -0
  22. data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -0
  23. data/app/views/components/lolita/{field_set → configuration/field_set}/_display.html.erb +1 -1
  24. data/app/views/components/lolita/configuration/list/_body.html.erb +5 -0
  25. data/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
  26. data/app/views/components/lolita/{list → configuration/list}/_checkbox_cell.html.erb +0 -0
  27. data/app/views/components/lolita/{list → configuration/list}/_checkbox_header.html.erb +0 -0
  28. data/app/views/components/lolita/configuration/list/_display.html.erb +12 -0
  29. data/app/views/components/lolita/configuration/list/_filter.html.erb +8 -0
  30. data/app/views/components/lolita/configuration/list/_header.html.erb +9 -0
  31. data/app/views/components/lolita/{list → configuration/list}/_header_cell.html.erb +0 -0
  32. data/app/views/components/lolita/{list → configuration/list}/_new_resource.html.erb +0 -0
  33. data/app/views/components/lolita/configuration/list/_paginator.html.erb +3 -0
  34. data/app/views/components/lolita/configuration/list/_row.html.erb +7 -0
  35. data/app/views/components/lolita/{list → configuration/list}/_title.html.erb +0 -0
  36. data/app/views/components/lolita/{list → configuration/list}/_tool_cell.html.erb +0 -0
  37. data/app/views/components/lolita/{list → configuration/list}/_tool_header.html.erb +0 -0
  38. data/app/views/components/lolita/configuration/tab/_display.html.erb +17 -0
  39. data/app/views/components/lolita/configuration/tab/_fields.html.erb +7 -0
  40. data/app/views/components/lolita/configuration/tab/content/_display.html.erb +1 -0
  41. data/app/views/components/lolita/configuration/tab/default/_display.html.erb +9 -0
  42. data/app/views/components/lolita/{tabs → configuration/tabs}/_display.html.erb +4 -3
  43. data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb +0 -0
  44. data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb_spec.rb +0 -0
  45. data/author +1 -1
  46. data/lib/lolita.rb +31 -12
  47. data/lib/lolita/adapter/active_record.rb +16 -5
  48. data/lib/lolita/adapter/mongoid.rb +2 -2
  49. data/lib/lolita/base_configuration.rb +44 -2
  50. data/lib/lolita/builder.rb +31 -14
  51. data/lib/lolita/configuration/column.rb +92 -86
  52. data/lib/lolita/configuration/columns.rb +65 -65
  53. data/lib/lolita/configuration/factory.rb +8 -8
  54. data/lib/lolita/configuration/field.rb +156 -100
  55. data/lib/lolita/configuration/field/array.rb +74 -0
  56. data/lib/lolita/configuration/field/big_decimal.rb +12 -0
  57. data/lib/lolita/configuration/field/boolean.rb +7 -5
  58. data/lib/lolita/configuration/field/date.rb +13 -0
  59. data/lib/lolita/configuration/field/integer.rb +7 -5
  60. data/lib/lolita/configuration/field/string.rb +8 -6
  61. data/lib/lolita/configuration/field/time.rb +13 -0
  62. data/lib/lolita/configuration/fields.rb +36 -0
  63. data/lib/lolita/configuration/filter.rb +63 -0
  64. data/lib/lolita/configuration/list.rb +101 -91
  65. data/lib/lolita/configuration/page.rb +1 -0
  66. data/lib/lolita/configuration/tab.rb +137 -131
  67. data/lib/lolita/configuration/tab/content.rb +14 -12
  68. data/lib/lolita/configuration/tab/default.rb +15 -13
  69. data/lib/lolita/configuration/tabs.rb +2 -2
  70. data/lib/lolita/controllers/component_helpers.rb +26 -14
  71. data/lib/lolita/controllers/internal_helpers.rb +14 -0
  72. data/lib/lolita/controllers/url_helpers.rb +47 -10
  73. data/lib/lolita/dbi/base.rb +50 -50
  74. data/lib/lolita/errors.rb +2 -2
  75. data/lib/lolita/hooks.rb +298 -0
  76. data/lib/lolita/hooks/named_hook.rb +122 -0
  77. data/lib/lolita/lazy_loader.rb +46 -46
  78. data/lib/lolita/mapping.rb +3 -2
  79. data/lib/lolita/navigation.rb +48 -0
  80. data/lib/lolita/observed_array.rb +7 -0
  81. data/lib/lolita/rails/routes.rb +29 -3
  82. data/lolita.gemspec +65 -48
  83. data/public/javascripts/lolita/tab.js +5 -0
  84. data/public/javascripts/rails.js +137 -137
  85. data/public/stylesheets/lolita/style.css +3 -1
  86. data/spec/builder_spec.rb +42 -0
  87. data/spec/configuration/field_spec.rb +29 -18
  88. data/spec/configuration/filter_spec.rb +60 -0
  89. data/spec/configuration/tab_spec.rb +28 -20
  90. data/spec/configuration/tabs_spec.rb +8 -4
  91. data/spec/controllers/lolita_rest_spec.rb +15 -0
  92. data/spec/hooks_spec.rb +191 -0
  93. data/spec/lolita_spec.rb +6 -4
  94. data/spec/navigation/tree_spec.rb +59 -0
  95. data/spec/rails_app/app/mongoid/post.rb +2 -0
  96. data/spec/rails_app/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
  97. data/spec/rails_app/config/application.rb +1 -0
  98. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +14 -0
  99. data/spec/simple_spec_helper.rb +1 -0
  100. data/spec/spec_helper.rb +1 -2
  101. metadata +66 -49
  102. data/README.md +0 -5
  103. data/app/helpers/components/lolita/list_component.rb +0 -9
  104. data/app/views/components/lolita/field/_collection.html.erb +0 -5
  105. data/app/views/components/lolita/field/_date.html.erb +0 -1
  106. data/app/views/components/lolita/field/_datetime.html.erb +0 -1
  107. data/app/views/components/lolita/field/_display.html.erb +0 -6
  108. data/app/views/components/lolita/field/_integer.html.erb +0 -1
  109. data/app/views/components/lolita/field/_label.html.erb +0 -1
  110. data/app/views/components/lolita/field/_select.html.erb +0 -1
  111. data/app/views/components/lolita/field/_text.html.erb +0 -27
  112. data/app/views/components/lolita/list/_body.html.erb +0 -5
  113. data/app/views/components/lolita/list/_display.html.erb +0 -11
  114. data/app/views/components/lolita/list/_header.html.erb +0 -9
  115. data/app/views/components/lolita/list/_paginator.html.erb +0 -4
  116. data/app/views/components/lolita/list/_row.html.erb +0 -7
  117. data/app/views/components/lolita/tab/_content.html.erb +0 -1
  118. data/app/views/components/lolita/tab/_default.html.erb +0 -11
  119. data/app/views/components/lolita/tab/_display.html.erb +0 -7
  120. data/app/views/components/lolita/tab/_fields.html.erb +0 -7
  121. data/lib/lolita/configuration/field/collection.rb +0 -71
  122. data/lib/lolita/configuration/field/datetime.rb +0 -10
  123. data/lib/lolita/configuration/field/disabled.rb +0 -10
  124. data/lib/lolita/configuration/field/password.rb +0 -10
  125. data/lib/lolita/configuration/field/text.rb +0 -10
  126. data/lib/lolita/hooks/base.rb +0 -58
  127. data/lib/lolita/hooks/component.rb +0 -15
  128. data/lib/lolita/hooks/hooks.rb +0 -15
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Lolita::Configuration::Filter do
4
+
5
+ before(:each) do
6
+ @dbi=Lolita::DBI::Base.new(Post)
7
+ end
8
+
9
+ it "should create new filter with block" do
10
+ Lolita::Configuration::Filter.new(@dbi) do
11
+
12
+ end
13
+ end
14
+
15
+ it "should create new filter without block" do
16
+ Lolita::Configuration::Filter.new(@dbi)
17
+ end
18
+
19
+ it "should give fields as arguments" do
20
+ list=Lolita::Configuration::List.new(@dbi)
21
+ list.filter :name, :is_public
22
+ list.filter.fields.size.should == 2
23
+ end
24
+
25
+ it "should add default search field if none is given" do
26
+ filter=Lolita::Configuration::Filter.new(@dbi)
27
+ filter.fields.size.should == 1
28
+ filter=Lolita::Configuration::Filter.new(@dbi){}
29
+ filter.fields.size.should == 1
30
+ end
31
+
32
+ it "should add some fields" do
33
+ filter=Lolita::Configuration::Filter.new(@dbi) do
34
+ fields :name, :is_public, :not_public
35
+ end
36
+ filter.fields.size.should == 3
37
+ end
38
+
39
+ it "should add some field with block" do
40
+ filter=Lolita::Configuration::Filter.new(@dbi) do
41
+ field :name do
42
+ type :integer
43
+ end
44
+ end
45
+ filter.fields.first.type.should == "integer"
46
+ end
47
+
48
+ it "should add some fields with block" do
49
+ filter=Lolita::Configuration::Filter.new(@dbi) do
50
+ fields :name, :is_public do
51
+ type :integer
52
+ end
53
+ field :created_at, :time
54
+ end
55
+ filter.fields.size.should == 3
56
+ filter.fields[0].type.should == "integer"
57
+ filter.fields[1].type.should == "integer"
58
+ filter.fields[2].type.should == "time"
59
+ end
60
+ end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  # temp class for extending tabs
4
- class Lolita::Configuration::MyTab < Lolita::Configuration::Tab
4
+ class Lolita::Configuration::Tab::My < Lolita::Configuration::Tab::Base
5
5
  def initialize(dbi,*args,&block)
6
6
  @type=:my
7
7
  super
@@ -15,15 +15,16 @@ describe Lolita::Configuration::Tab do
15
15
  @dbi=Lolita::DBI::Base.new(Post)
16
16
  end
17
17
 
18
+ let(:tab_class){Lolita::Configuration::Tab::Base}
18
19
  describe "create extended tabs" do
19
20
 
20
21
  context "tab class is child class of ::Tab class " do
21
22
  it "should create new" do
22
- Lolita::Configuration::MyTab.new(@dbi).type.should == :my
23
+ Lolita::Configuration::Tab::My.new(@dbi).type.should == :my
23
24
  end
24
25
 
25
26
  it "should create new with block" do
26
- Lolita::Configuration::MyTab.new(@dbi) do
27
+ Lolita::Configuration::Tab::My.new(@dbi) do
27
28
  title "My New tab"
28
29
  end.title.should == "My New tab"
29
30
  end
@@ -33,33 +34,33 @@ describe Lolita::Configuration::Tab do
33
34
 
34
35
  describe "add tab" do
35
36
  it "should recognize type of tab added and create it as a related class object" do
36
- Lolita::Configuration::Tab.add(@dbi){ field(:email)}.class.to_s.should=="Lolita::Configuration::DefaultTab"
37
- Lolita::Configuration::Tab.add(@dbi,:my).class.to_s.should == "Lolita::Configuration::MyTab"
37
+ Lolita::Configuration::Tab.add(@dbi){ field(:email)}.class.to_s.should=="Lolita::Configuration::Tab::Default"
38
+ Lolita::Configuration::Tab.add(@dbi,:my).class.to_s.should == "Lolita::Configuration::Tab::My"
38
39
  Lolita::Configuration::Tab.add(@dbi) {
39
40
  type :my
40
- }.class.to_s.should == "Lolita::Configuration::MyTab"
41
+ }.class.to_s.should == "Lolita::Configuration::Tab::My"
41
42
  end
42
43
 
43
44
  it "should raise error when tab is not recognized" do
44
45
  lambda{
45
46
  Lolita::Configuration::Tab.add(@dbi,:yourtab)
46
- }.should raise_error(Lolita::TabNotFoundError)
47
+ }.should raise_error(Lolita::ConfigurationClassNotFound)
47
48
  end
48
49
  end
49
50
 
50
51
  it "should create tab" do
51
- Lolita::Configuration::Tab.new(@dbi,:content)
52
+ tab_class.new(@dbi,:content)
52
53
  end
53
54
 
54
55
  it "should allow to set title" do
55
- tab=Lolita::Configuration::Tab.new(@dbi,:content) do
56
+ tab=tab_class.new(@dbi,:content) do
56
57
  title "My tab"
57
58
  end
58
59
  tab.title.should == "My tab"
59
60
  end
60
61
 
61
62
  it "should have default title that is humanized type" do
62
- tab=Lolita::Configuration::Tab.new(@dbi,:content)
63
+ tab=tab_class.new(@dbi,:content)
63
64
  tab.title.should=="Content"
64
65
  end
65
66
 
@@ -70,19 +71,19 @@ describe Lolita::Configuration::Tab do
70
71
  end
71
72
 
72
73
  it "should create tab when attributes are given" do
73
- tab=Lolita::Configuration::Tab.new(@dbi,:fields=>[{:name=>"field one"}])
74
+ tab=tab_class.new(@dbi,:fields=>[{:name=>"field one"}])
74
75
  tab.fields.size.should == 1
75
76
  end
76
77
 
77
78
  it "should create tab when block is given" do
78
- tab=Lolita::Configuration::Tab.new(@dbi) do
79
+ tab=tab_class.new(@dbi) do
79
80
  field :name=>"field one"
80
81
  end
81
82
  tab.fields.size.should == 1
82
83
  end
83
84
 
84
85
  it "should allow add fieldset to tab" do
85
- tab=Lolita::Configuration::Tab.new(@dbi) do
86
+ tab=tab_class.new(@dbi) do
86
87
  field_set("Person information") do
87
88
  field :name=>"field one"
88
89
  end
@@ -91,7 +92,7 @@ describe Lolita::Configuration::Tab do
91
92
  end
92
93
 
93
94
  it "should keep order for fields added in tab and in tab fieldsets" do
94
- tab=Lolita::Configuration::Tab.new(@dbi) do
95
+ tab=tab_class.new(@dbi) do
95
96
  field :name=>"one"
96
97
  field_set("Fieldset") do
97
98
  field :name=>"two"
@@ -103,11 +104,11 @@ describe Lolita::Configuration::Tab do
103
104
  end
104
105
  field :name=>"six"
105
106
  end
106
- tab.fields.collect{|f| f.name}.should == [:"one",:"two",:"three",:"four",:"five",:"six"]
107
+ tab.fields.collect{|f| f.name }.should == [:"one",:"two",:"three",:"four",:"five",:"six"]
107
108
  end
108
109
 
109
110
  it "should get fields from fieldset" do
110
- tab=Lolita::Configuration::Tab.new(@dbi) do
111
+ tab=tab_class.new(@dbi) do
111
112
  field :name=>"one"
112
113
  field_set("Fieldset") do
113
114
  field :name=>"two"
@@ -118,14 +119,14 @@ describe Lolita::Configuration::Tab do
118
119
  end
119
120
 
120
121
  it "should add default fields for any tab when specified" do
121
- tab=Lolita::Configuration::Tab.new(@dbi,:images) do
122
+ tab=tab_class.new(@dbi,:images) do
122
123
  default_fields
123
124
  end
124
125
  tab.fields.size.should > 0
125
126
  end
126
127
 
127
128
  it "should add nested fields" do
128
- tab=Lolita::Configuration::Tab.new(@dbi) do
129
+ tab=tab_class.new(@dbi) do
129
130
  default_fields
130
131
  nested_fields_for("Comment") do
131
132
  default_fields
@@ -137,7 +138,7 @@ describe Lolita::Configuration::Tab do
137
138
  end
138
139
 
139
140
  it "should detect that field is nested" do
140
- tab=Lolita::Configuration::Tab.new(@dbi) do
141
+ tab=tab_class.new(@dbi) do
141
142
  default_fields
142
143
  nested_fields_for("Comment") do
143
144
  default_fields
@@ -147,7 +148,7 @@ describe Lolita::Configuration::Tab do
147
148
  end
148
149
 
149
150
  it "should return nested fields for specified class" do
150
- tab=Lolita::Configuration::Tab.new(@dbi) do
151
+ tab=tab_class.new(@dbi) do
151
152
  default_fields
152
153
  nested_fields_for("Comment") do
153
154
  default_fields
@@ -156,5 +157,12 @@ describe Lolita::Configuration::Tab do
156
157
  tab.nested_fields_of("Comment").size.should > 0
157
158
  end
158
159
 
160
+ it "should return field with given name" do
161
+ tab=tab_class.new(@dbi) do
162
+ default_fields
163
+ end
164
+ tab.fields.by_name(:title).name.should == :title
165
+ end
166
+
159
167
  end
160
168
 
@@ -2,7 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  module Lolita
4
4
  module Configuration
5
- class ImagesTab < Lolita::Configuration::Tab
5
+ module Tab
6
+ class Images < Lolita::Configuration::Tab::Base
7
+ end
8
+ class Translation < Lolita::Configuration::Tab::Base
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -30,7 +34,7 @@ describe Lolita::Configuration::Tabs do
30
34
  end
31
35
 
32
36
  it "should create tabs when specified as arguments" do
33
- tabs=Lolita::Configuration::Tabs.new(@dbi,:tabs=>[Lolita::Configuration::Tab.new(@dbi,:content)])
37
+ tabs=Lolita::Configuration::Tabs.new(@dbi,:tabs=>[Lolita::Configuration::Tab::Base.new(@dbi,:content)])
34
38
  tabs.size.should == 1
35
39
  end
36
40
 
@@ -75,8 +79,8 @@ describe Lolita::Configuration::Tabs do
75
79
  tabs=Lolita::Configuration::Tabs.new(@dbi,:default=>:content)
76
80
  tabs<<:images
77
81
  tabs<<:translation
78
- tabs[tabs.size-2].class.should == Lolita::Configuration::Tab
79
- tabs[tabs.size-1].class.should == Lolita::Configuration::Tab
82
+ tabs[tabs.size-2].class.should == Lolita::Configuration::Tab::Images
83
+ tabs[tabs.size-1].class.should == Lolita::Configuration::Tab::Translation
80
84
  end
81
85
 
82
86
  it "should return all tab names" do
@@ -21,5 +21,20 @@ describe Lolita::RestController do
21
21
  get :new
22
22
  response.body.should =~/select|input/
23
23
  end
24
+
25
+ it "should change name of field's label to 'bar' if title 'bar' given in fields configuration" do
26
+ tab = Post.lolita.tabs.first
27
+ tab.type.should == :content
28
+ tab.fields.by_name(:title).title = "foobar"
29
+ get :new
30
+ response.body.should =~/foobar/
31
+ end
32
+
33
+ it "should display inline error messages if validations fail"
34
+
35
+ it "should display all error messages at top of from if a validations fail"
36
+
37
+ it "should use field.title instead of field.name when displaying all error messages at top of form"
38
+
24
39
  end
25
40
 
@@ -0,0 +1,191 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/simple_spec_helper')
2
+
3
+
4
+ class MyClass
5
+ def self.value(value=nil)
6
+ @value=value if value
7
+ @value
8
+ end
9
+
10
+ attr_accessor :name
11
+ def initialize
12
+ self.fire(:after_init)
13
+ end
14
+
15
+ def save
16
+ self.fire(:before_save)
17
+ end
18
+ end
19
+
20
+ class Counter
21
+ def self.set(val)
22
+ @value=val
23
+ end
24
+
25
+ def self.get
26
+ @value
27
+ end
28
+ end
29
+ describe Lolita::Hooks do
30
+ after(:each) do
31
+ MyClass.clear_hooks if MyClass.respond_to?(:clear_hooks)
32
+ Counter.clear_hooks if Counter.respond_to?(:clear_hooks)
33
+ MyClass.value(0)
34
+ end
35
+
36
+ it "should be possible to define hooks for class" do
37
+ MyClass.send(:include, Lolita::Hooks)
38
+ MyClass.add_hook(:after_load)
39
+ MyClass.hooks.should have(1).item
40
+ end
41
+
42
+ it "should accept callback for class" do
43
+ MyClass.send(:include, Lolita::Hooks)
44
+ MyClass.add_hook(:after_load)
45
+ MyClass.after_load do
46
+ 1+1
47
+ end
48
+ MyClass.callbacks[:after_load][:blocks].should have(1).item
49
+ MyClass.callbacks[:after_load][:methods].should have(0).items
50
+ end
51
+
52
+ it "should append methods and blocks to callbacks" do
53
+ MyClass.send(:include,Lolita::Hooks)
54
+ MyClass.add_hook(:after_load)
55
+ MyClass.after_load {}
56
+ MyClass.after_load {}
57
+ MyClass.after_load :method
58
+ MyClass.after_load :other_method
59
+ MyClass.callbacks[:after_load][:blocks].should have(2).items
60
+ MyClass.callbacks[:after_load][:methods].should have(2).items
61
+ end
62
+
63
+ context "Firing callbacks" do
64
+
65
+ before(:each) do
66
+ MyClass.send(:include, Lolita::Hooks)
67
+ MyClass.add_hook(:after_load)
68
+ MyClass.add_hook(:after_init)
69
+ MyClass.add_hook(:before_save)
70
+ end
71
+
72
+ it "should ran on instance when called on one" do
73
+ MyClass.value(0)
74
+ MyClass.after_init do
75
+ self.name="name"
76
+ end
77
+ object=MyClass.new
78
+ object.name.should == "name"
79
+ end
80
+
81
+ it "should accept callbacks for any instance" do
82
+ object=MyClass.new
83
+ object.before_save do
84
+ self.name="new name"
85
+ end
86
+ object.save
87
+ object.name.should == "new name"
88
+ end
89
+
90
+ it "should detect hook by name" do
91
+ MyClass.after_load do
92
+ value(true)
93
+ end
94
+ MyClass.fire(:after_load)
95
+ MyClass.value.should be_true
96
+ end
97
+
98
+ it "should have named fire method" do
99
+ MyClass.after_load {
100
+ MyClass.value(MyClass.value()+1)
101
+ }
102
+ object=MyClass.new
103
+ MyClass.fire_after_load
104
+ object.fire_after_load
105
+ MyClass.value.should == 2
106
+ end
107
+
108
+ it "should execute callback each time" do
109
+ MyClass.value(0)
110
+ MyClass.after_load do
111
+ value(value()+1)
112
+ end
113
+ MyClass.fire(:after_load)
114
+ MyClass.fire(:after_load)
115
+ MyClass.value.should == 2
116
+ end
117
+
118
+
119
+ context "wrap around" do
120
+
121
+ it "should allow to wrap around when #fire receive block" do
122
+ MyClass.after_load do
123
+ value("first")
124
+ let_content()
125
+ value("second")
126
+ end
127
+
128
+ MyClass.fire(:after_load) do
129
+ value().should=="first"
130
+ end
131
+ MyClass.value.should == "second"
132
+ end
133
+ end
134
+ end
135
+
136
+
137
+ describe "named callbacks" do
138
+ before(:each) do
139
+ Lolita::Hooks::NamedHook.add(:components) unless Lolita::Hooks::NamedHook.exist?(:component)
140
+ end
141
+
142
+ after(:each) do
143
+ Lolita::Hooks.components.clear_hooks
144
+ end
145
+
146
+ it "should add callbacks" do
147
+ Lolita::Hooks.components.add_hook(:before)
148
+ Lolita::Hooks.components.hooks.should have(1).hook
149
+ end
150
+
151
+ it "should filter by name" do
152
+ Lolita::Hooks.components.add_hook(:before)
153
+ Counter.set(0)
154
+ Lolita::Hooks.component(:"list").before do
155
+ Counter.set(Counter.get+1)
156
+ end
157
+
158
+ Lolita::Hooks.component(:"tab").before do
159
+ Counter.set(Counter.get+1)
160
+ end
161
+
162
+ Lolita::Hooks.component(:"list").fire(:before)
163
+ Counter.get.should == 1
164
+ end
165
+
166
+ it "should run on each named object when defined for all collection" do
167
+ Lolita::Hooks.components.add_hook(:after)
168
+ Counter.set(0)
169
+ Lolita::Hooks.components.after do
170
+ Counter.set(Counter.get+1)
171
+ end
172
+ Lolita::Hooks.component(:"list").fire(:after)
173
+ Lolita::Hooks.component(:"tab").fire(:after)
174
+ Counter.get.should == 2
175
+ end
176
+
177
+ it "should run all named hook callbacks when fired on named collection" do
178
+ Lolita::Hooks.components.add_hook(:after)
179
+ Counter.set(0)
180
+ Lolita::Hooks.component(:"list").after do
181
+ Counter.set(Counter.get+1)
182
+ end
183
+ Lolita::Hooks.component(:"tab").after do
184
+ Counter.set(Counter.get+1)
185
+ end
186
+ Lolita::Hooks.components.fire(:after)
187
+ Counter.get.should == 2
188
+ end
189
+
190
+ end
191
+ end