formic 0.1.0

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.
Files changed (67) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +40 -0
  3. data/README.rdoc +54 -0
  4. data/Rakefile +35 -0
  5. data/VERSION +1 -0
  6. data/javascripts/jquery-1.6.2.min.js +18 -0
  7. data/javascripts/jquery-ui-1.8.16.custom.min.js +791 -0
  8. data/lib/formic/base.rb +65 -0
  9. data/lib/formic/button.rb +22 -0
  10. data/lib/formic/checkbox.rb +9 -0
  11. data/lib/formic/file.rb +8 -0
  12. data/lib/formic/form.rb +69 -0
  13. data/lib/formic/helper.rb +39 -0
  14. data/lib/formic/hidden.rb +10 -0
  15. data/lib/formic/input.rb +41 -0
  16. data/lib/formic/list.rb +5 -0
  17. data/lib/formic/list_item.rb +13 -0
  18. data/lib/formic/password.rb +10 -0
  19. data/lib/formic/railtie.rb +12 -0
  20. data/lib/formic/selection.rb +5 -0
  21. data/lib/formic/tab.rb +23 -0
  22. data/lib/formic/tab_panel.rb +12 -0
  23. data/lib/formic/textarea.rb +5 -0
  24. data/lib/formic.rb +17 -0
  25. data/spec/formic/base_spec.rb +148 -0
  26. data/spec/formic/button_spec.rb +55 -0
  27. data/spec/formic/checkbox_spec.rb +30 -0
  28. data/spec/formic/file_spec.rb +30 -0
  29. data/spec/formic/form_spec.rb +136 -0
  30. data/spec/formic/helper_spec.rb +60 -0
  31. data/spec/formic/hidden_spec.rb +30 -0
  32. data/spec/formic/input_spec.rb +131 -0
  33. data/spec/formic/list_item_spec.rb +25 -0
  34. data/spec/formic/list_spec.rb +22 -0
  35. data/spec/formic/password_spec.rb +37 -0
  36. data/spec/formic/selection_spec.rb +35 -0
  37. data/spec/formic/tab_panel_spec.rb +26 -0
  38. data/spec/formic/tab_spec.rb +69 -0
  39. data/spec/formic/textarea_spec.rb +35 -0
  40. data/spec/formic_spec_helper.rb +23 -0
  41. data/spec/spec_helper.rb +9 -0
  42. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  43. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  44. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  45. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  46. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  47. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  48. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  49. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  50. data/stylesheets/jquery-ui/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  51. data/stylesheets/jquery-ui/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  52. data/stylesheets/jquery-ui/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  53. data/stylesheets/jquery-ui/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  54. data/stylesheets/jquery-ui/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  55. data/stylesheets/jquery-ui/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  56. data/stylesheets/jquery-ui/ui-lightness/jquery-ui-1.8.16.custom.css +568 -0
  57. data/views/formic/default/_button.html.haml +1 -0
  58. data/views/formic/default/_form.html.haml +12 -0
  59. data/views/formic/default/_hidden.html.haml +1 -0
  60. data/views/formic/default/_input.html.haml +4 -0
  61. data/views/formic/default/_list.html.haml +3 -0
  62. data/views/formic/default/_list_item.html.haml +1 -0
  63. data/views/formic/default/_selection.html.haml +13 -0
  64. data/views/formic/default/_tab.html.haml +3 -0
  65. data/views/formic/default/_tab_panel.html.haml +9 -0
  66. data/views/formic/default/_textarea.html.haml +4 -0
  67. metadata +216 -0
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Form do
4
+
5
+ before(:each) do
6
+ @page = Object.new
7
+ @options = {}
8
+ @block = Proc.new {}
9
+ @model = Object.new
10
+ end
11
+
12
+ context "#initialize" do
13
+ it "should be initialize with action, options" do
14
+ form = Formic::Form.new @page, @options, &@block
15
+ form.should have_template 'formic/default/form'
16
+ end
17
+
18
+ it "default method to POST" do
19
+ form = Formic::Form.new @page, @options, &@block
20
+ form.options[:method].should == 'POST'
21
+ end
22
+ end
23
+
24
+ shared_examples_for "all methods" do
25
+ it "should return the object" do
26
+ @result.should == @form
27
+ end
28
+
29
+ it "should set the content block" do
30
+ @form.content.should == @block
31
+ end
32
+
33
+ it "should have the class form" do
34
+ @form.has_class?('form').should be_true
35
+ end
36
+ end
37
+
38
+ context "#put" do
39
+ before(:each) do
40
+ @form = Formic::Form.new @page
41
+ @result = @form.put @options, &@block
42
+ end
43
+
44
+ it_should_behave_like 'all methods'
45
+
46
+ it "should set the option _method to PUT and method to POST" do
47
+ @form.options[:method].should == 'POST'
48
+ @form.options[:_method].should == 'PUT'
49
+ end
50
+ end
51
+
52
+ shared_examples_for "all methods that action on model" do
53
+ it_should_behave_like 'all methods'
54
+ it "should set the model value" do
55
+ @form.model.should == @model
56
+ end
57
+
58
+ it "should not override the action if it is already in options" do
59
+ @form = Formic::Form.new @page, @options.merge( :action => 'some_action' ), &@block
60
+ @form.options[:action].should == 'some_action'
61
+ end
62
+ end
63
+
64
+ context '#create' do
65
+ before(:each) do
66
+ @form = Formic::Form.new @page
67
+ mock(@page).url_for(@model) {'/models/1'}
68
+ @result = @form.create @model, @options, &@block
69
+ end
70
+
71
+ it_should_behave_like "all methods that action on model"
72
+
73
+ it "should have action create" do
74
+ @form.action.should == :create
75
+ end
76
+
77
+ it "should test that" do
78
+ @form.should have_action( '/models/1' )
79
+ @form.should have_class( 'create_object_form' )
80
+ @form.should have_title( 'New Object' )
81
+ end
82
+
83
+ it "should allow to pass in action" do
84
+ form = Formic::Form.new @page
85
+ form.create @model, {:action => 'some/action'}, &@block
86
+ form.options[:action].should == 'some/action'
87
+ end
88
+ end
89
+
90
+ context '#edit' do
91
+ before(:each) do
92
+ @form = Formic::Form.new @page
93
+ mock(@page).url_for(@model) {'/models/1'}
94
+ @result = @form.edit @model, @options, &@block
95
+ end
96
+
97
+ it "should have action edit" do
98
+ @form.action.should == :edit
99
+ end
100
+
101
+ it_should_behave_like "all methods that action on model"
102
+
103
+ it "should test that" do
104
+ @form.should have_action '/models/1'
105
+ @form.should have_class 'edit_object_form'
106
+ @form.should have_title( 'Edit Object' )
107
+ end
108
+
109
+ it "should generate put method" do
110
+ @form.options[:method].should == 'POST'
111
+ @form.options[:_method].should == 'PUT'
112
+ end
113
+ end
114
+
115
+ context "#method_missing" do
116
+ context "with model" do
117
+ before(:each) do
118
+ @form = Formic::Form.new @page
119
+ mock(@page).url_for(@model) {'/models/1'}
120
+ @result = @form.do_something @model, @options, &@block
121
+ end
122
+
123
+ it "should have action" do
124
+ @form.action.should == :do_something
125
+ end
126
+
127
+ it_should_behave_like "all methods that action on model"
128
+
129
+ it "should test that" do
130
+ @form.should have_action '/models/1/do_something'
131
+ @form.should have_class 'do_something_object_form'
132
+ @form.should have_title( 'Do Something Object' )
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/formic/helper'
3
+
4
+ describe Formic::Helper do
5
+ before(:each) do
6
+ @page = Object.new
7
+ @page.extend Formic::Helper
8
+
9
+ @options = {}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#get_class" do
14
+ it "should return the class base on the name" do
15
+ @page.get_class(:list).should == Formic::List
16
+ end
17
+
18
+ it "should return class with underscore" do
19
+ @page.get_class(:list_item).should == Formic::ListItem
20
+ end
21
+ end
22
+
23
+ [
24
+ :selection,
25
+ :input,
26
+ :password,
27
+ :checkbox,
28
+ :list,
29
+ :list_item,
30
+ :form,
31
+ :tab_panel,
32
+ :button,
33
+ :textarea
34
+ ].each do |element|
35
+
36
+ it "should repond to #{element}" do
37
+ @page.should respond_to element
38
+ end
39
+
40
+ it "should be initilize the object with page" do
41
+ @object = @page.send(element, @options, &@block)
42
+ @object.page.should == @page
43
+ end
44
+ end
45
+
46
+ context "#tab" do
47
+ before(:each) do
48
+ tab_panel = @page.tab_panel @options, &@block
49
+ end
50
+
51
+ it "should repond to tab" do
52
+ @page.should respond_to :tab
53
+ end
54
+
55
+ it "should be initilize the object with page" do
56
+ @object = @page.tab.style 'Some Title', @options, &@block
57
+ @object.page.should == @page
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Hidden do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#file" do
14
+ before(:each) do
15
+ @hidden = Formic::Hidden.new @page, 'name', @options, &@block
16
+ end
17
+
18
+ it "should have template formic/default/hidden" do
19
+ @hidden.template.should == 'formic/default/hidden'
20
+ end
21
+
22
+ it "should have type hidden" do
23
+ @hidden.options[:type].should == 'hidden'
24
+ end
25
+
26
+ it "should set field" do
27
+ @hidden.field.should == 'name'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Input do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#initialize" do
14
+ before(:each) do
15
+ @input = Formic::Input.new @page, 'input_name', @options
16
+ end
17
+ it "should have formic/default/input as default template" do
18
+ @input.should have_template 'formic/default/input'
19
+ end
20
+
21
+ it "should have correct class name" do
22
+ @input.should have_class 'input'
23
+ end
24
+
25
+ it "should have correct input name" do
26
+ @input.should have_name 'input_name'
27
+ end
28
+ end
29
+
30
+ context "interact with form" do
31
+ context "form with model" do
32
+ before(:each) do
33
+ @form = Formic::Form.new @page
34
+ @form.create @model
35
+ mock(@model).send(:some_name) {'model value'}
36
+ @input = Formic::Input.new @page, 'some_name', @options
37
+ end
38
+
39
+ it "should return the current form if input is inside a form" do
40
+ @input.form.should == @form
41
+ end
42
+
43
+ it "should have name which is model[field]" do
44
+ @input.should have_name 'object[some_name]'
45
+ end
46
+
47
+ it "should have value for field" do
48
+ @input.field.should == 'some_name'
49
+ end
50
+
51
+ it "should have value which is the model value" do
52
+ @input.should have_value 'model value'
53
+ end
54
+
55
+ it "should not override if the value is given" do
56
+ input = Formic::Form.new @page
57
+ input = Formic::Input.new @page, 'some_name', {:value => 'some other value'}
58
+ input.should have_value 'some other value'
59
+ end
60
+
61
+ after(:each) do
62
+ @input.to_s
63
+ @form.to_s
64
+ end
65
+ end
66
+
67
+ context "form without model" do
68
+ before(:each) do
69
+ @form = Formic::Form.new @page
70
+ @input = Formic::Input.new @page, 'some_name', @options
71
+ end
72
+
73
+ it "should have name which is given" do
74
+ @input.should have_name 'some_name'
75
+ end
76
+
77
+ it "should be allowed to passed in name" do
78
+ input = Formic::Input.new @page
79
+ input.required :name => 'passed_in_name'
80
+ input.options[:name].should == 'passed_in_name'
81
+ end
82
+
83
+ after(:each) do
84
+ @input.to_s
85
+ @form.to_s
86
+ end
87
+ end
88
+
89
+ context "#method missing" do
90
+ before(:each) do
91
+ @input = Formic::Input.new @page
92
+ @result = @input.small 'name', @options, &@block
93
+ end
94
+
95
+ it "should add the class" do
96
+ @input.should have_class 'small'
97
+ end
98
+
99
+ it "should set the field" do
100
+ @input.field.should == 'name'
101
+ end
102
+
103
+ it "should return the object" do
104
+ @input.should == @result
105
+ end
106
+
107
+ context "with form model" do
108
+ it "should have correct name" do
109
+ form = Formic::Form.new @page
110
+ form.create @model
111
+ mock(@model).send(:some_name) {'model value'}
112
+ input = Formic::Input.new @page
113
+ input.required 'some_name', @options
114
+ input.should have_name 'object[some_name]'
115
+ end
116
+ end
117
+
118
+ context "#label" do
119
+ it "should be generated from field" do
120
+ input = Formic::Input.new @page, 'some_name', @options
121
+ input.label.should == 'Some Name'
122
+ end
123
+
124
+ it "could be passed in via option" do
125
+ input = Formic::Input.new @page, 'some_name', :label => 'Some Label'
126
+ input.label.should == 'Some Label'
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::ListItem do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page).render
7
+
8
+ @options = {}
9
+ @block = Proc.new {}
10
+ end
11
+
12
+ context "#initialize" do
13
+ before(:each) do
14
+ @list_item = Formic::ListItem.new @page, 'List Item Content', @options, &@block
15
+ end
16
+
17
+ it "should have template formic/default/list_item" do
18
+ @list_item.template.should == 'formic/default/list_item'
19
+ end
20
+
21
+ it "it should initialize with items" do
22
+ @list_item.text.should == 'List Item Content'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::List do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#initialize" do
14
+ before(:each) do
15
+ @input = Formic::List.new @page, @options, &@block
16
+ end
17
+
18
+ it "should have template formic/default/list" do
19
+ @input.template.should == 'formic/default/list'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Password do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#initialize" do
14
+ before(:each) do
15
+ @input = Formic::Password.new @page, 'name', @options, &@block
16
+ end
17
+
18
+ it "should have template formic/default/input" do
19
+ @input.template.should == 'formic/default/input'
20
+ end
21
+
22
+ it "should have type hidden" do
23
+ @input.options[:type].should == 'password'
24
+ end
25
+
26
+ it "should not have value" do
27
+ input = Formic::Password.new @page, 'name', {:value => 'some value'}, &@block
28
+ input.some_style 'name', {:value => 'some other value'}, &@block
29
+ input.options[:value].should be_blank
30
+
31
+ end
32
+
33
+ it "should set field value" do
34
+ @input.field.should == 'name'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Selection do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {:value => 'some value'}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#initialize" do
14
+ before(:each) do
15
+ @selection = Formic::Selection.new @page, 'name', @options, &@block
16
+ end
17
+
18
+ it "should have template formic/default/selection" do
19
+ @selection.template.should == 'formic/default/selection'
20
+ end
21
+
22
+ it "should have value for field" do
23
+ @selection.options[:value].should == 'some value'
24
+ end
25
+
26
+ it "should have class selection" do
27
+ @selection.should have_class 'selection'
28
+ end
29
+
30
+ it "should initilize other attributes" do
31
+ @selection.content.should == @block
32
+ @selection.field.should == 'name'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::TabPanel do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#tab_panel" do
14
+ before(:each) do
15
+ @tab_panel = Formic::TabPanel.new @page, @options, &@block
16
+ end
17
+
18
+ it "should have template formic/default/tab_panel" do
19
+ @tab_panel.template.should == 'formic/default/tab_panel'
20
+ end
21
+
22
+ it "should have class tab_panel" do
23
+ @tab_panel.should have_class 'tab_panel'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Tab do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @tab_panel = Formic::TabPanel.new @page
10
+ @options = {:key => 'value'}
11
+ @block = Proc.new {}
12
+ end
13
+
14
+ context "#initialize" do
15
+ before(:each) do
16
+ @tab = Formic::Tab.new @page, 'title', @options, &@block
17
+ end
18
+
19
+ it "should have template formic/default/tab" do
20
+ @tab.template.should == 'formic/default/tab'
21
+ end
22
+
23
+ it "should have an id" do
24
+ @tab.options[:id].should == 'title_tab'
25
+ end
26
+
27
+ it "should have title do" do
28
+ @tab.title.should == 'title'
29
+ end
30
+
31
+ context "#tab_panel" do
32
+ it "should find the latest tab panel" do
33
+ @tab.tab_panel.should == @tab_panel
34
+ end
35
+
36
+ it "should add itself to the tab_panel tabs" do
37
+ @tab_panel.tabs.last.should == @tab
38
+ end
39
+ end
40
+
41
+ after(:each) do
42
+ @tab.to_s
43
+ end
44
+ end
45
+
46
+ context "#method_missing" do
47
+ before(:each) do
48
+ @tab = Formic::Tab.new @page
49
+ @tab.style 'title', @options, &@block
50
+ end
51
+
52
+ it 'should add the class' do
53
+ @tab.should have_class 'style'
54
+ end
55
+
56
+ it 'should have content' do
57
+ @tab.content.should == @block
58
+ end
59
+
60
+ it 'should merge options' do
61
+ @tab.options[:key].should == 'value'
62
+
63
+ end
64
+
65
+ after(:each) do
66
+ @tab.to_s
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formic::Textarea do
4
+ before(:each) do
5
+ @model = Object.new
6
+ stub(@page = Object.new).url_for(@model) {'/models/1'}
7
+ stub(@page).render
8
+
9
+ @options = {:value => 'some value'}
10
+ @block = Proc.new {}
11
+ end
12
+
13
+ context "#initialize" do
14
+ before(:each) do
15
+ @textarea = Formic::Textarea.new @page, 'name', @options, &@block
16
+ end
17
+
18
+ it "should have template formic/default/textarea" do
19
+ @textarea.template.should == 'formic/default/textarea'
20
+ end
21
+
22
+ it "should have value for field" do
23
+ @textarea.options[:value].should == 'some value'
24
+ end
25
+
26
+ it "should have class textarea" do
27
+ @textarea.should have_class 'textarea'
28
+ end
29
+
30
+ it "should initilize other attributes" do
31
+ @textarea.content.should == @block
32
+ @textarea.field.should == 'name'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ module Formic
2
+ class Base
3
+ def has_template? template
4
+ return self.template == template
5
+ end
6
+
7
+ def has_action? action
8
+ self.options[:action] == action
9
+ end
10
+
11
+ def has_name? name
12
+ self.options[:name] == name
13
+ end
14
+
15
+ def has_value? value
16
+ self.options[:value] == value
17
+ end
18
+
19
+ def has_title? title
20
+ self.options[:title] == title
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require_relative '../lib/formic'
5
+ require_relative 'formic_spec_helper'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rr
9
+ end