lolita 3.0.7 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GUIDELINE +4 -0
- data/README.rdoc +50 -0
- data/VERSION +1 -1
- data/app/controllers/lolita/rest_controller.rb +27 -11
- data/app/helpers/components/lolita/configuration/list_component.rb +11 -0
- data/app/helpers/lolita_helper.rb +1 -1
- data/app/views/components/lolita/configuration/field/_display.html.erb +9 -0
- data/app/views/components/lolita/configuration/field/_label.html.erb +1 -0
- data/app/views/components/lolita/{field → configuration/field}/_object.html.erb +0 -0
- data/app/views/components/lolita/configuration/field/array/_display.html.erb +5 -0
- data/app/views/components/lolita/configuration/field/array/habtm/_display.html.erb +26 -0
- data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +5 -0
- data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +1 -0
- data/app/views/components/lolita/{field/_boolean.html.erb → configuration/field/boolean/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/date/_display.html.erb +1 -0
- data/app/views/components/lolita/{field/_string.html.erb → configuration/field/float/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/integer/_display.html.erb +1 -0
- data/app/views/components/lolita/configuration/field/string/_display.html.erb +5 -0
- data/app/views/components/lolita/{field/_disabled.html.erb → configuration/field/string/disabled/_display.html.erb} +0 -0
- data/app/views/components/lolita/{field/_password.html.erb → configuration/field/string/password/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +34 -0
- data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -0
- data/app/views/components/lolita/{field_set → configuration/field_set}/_display.html.erb +1 -1
- data/app/views/components/lolita/configuration/list/_body.html.erb +5 -0
- data/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_checkbox_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_checkbox_header.html.erb +0 -0
- data/app/views/components/lolita/configuration/list/_display.html.erb +12 -0
- data/app/views/components/lolita/configuration/list/_filter.html.erb +8 -0
- data/app/views/components/lolita/configuration/list/_header.html.erb +9 -0
- data/app/views/components/lolita/{list → configuration/list}/_header_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_new_resource.html.erb +0 -0
- data/app/views/components/lolita/configuration/list/_paginator.html.erb +3 -0
- data/app/views/components/lolita/configuration/list/_row.html.erb +7 -0
- data/app/views/components/lolita/{list → configuration/list}/_title.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_tool_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_tool_header.html.erb +0 -0
- data/app/views/components/lolita/configuration/tab/_display.html.erb +17 -0
- data/app/views/components/lolita/configuration/tab/_fields.html.erb +7 -0
- data/app/views/components/lolita/configuration/tab/content/_display.html.erb +1 -0
- data/app/views/components/lolita/configuration/tab/default/_display.html.erb +9 -0
- data/app/views/components/lolita/{tabs → configuration/tabs}/_display.html.erb +4 -3
- data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb +0 -0
- data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb_spec.rb +0 -0
- data/author +1 -1
- data/lib/lolita.rb +31 -12
- data/lib/lolita/adapter/active_record.rb +16 -5
- data/lib/lolita/adapter/mongoid.rb +2 -2
- data/lib/lolita/base_configuration.rb +44 -2
- data/lib/lolita/builder.rb +31 -14
- data/lib/lolita/configuration/column.rb +92 -86
- data/lib/lolita/configuration/columns.rb +65 -65
- data/lib/lolita/configuration/factory.rb +8 -8
- data/lib/lolita/configuration/field.rb +156 -100
- data/lib/lolita/configuration/field/array.rb +74 -0
- data/lib/lolita/configuration/field/big_decimal.rb +12 -0
- data/lib/lolita/configuration/field/boolean.rb +7 -5
- data/lib/lolita/configuration/field/date.rb +13 -0
- data/lib/lolita/configuration/field/integer.rb +7 -5
- data/lib/lolita/configuration/field/string.rb +8 -6
- data/lib/lolita/configuration/field/time.rb +13 -0
- data/lib/lolita/configuration/fields.rb +36 -0
- data/lib/lolita/configuration/filter.rb +63 -0
- data/lib/lolita/configuration/list.rb +101 -91
- data/lib/lolita/configuration/page.rb +1 -0
- data/lib/lolita/configuration/tab.rb +137 -131
- data/lib/lolita/configuration/tab/content.rb +14 -12
- data/lib/lolita/configuration/tab/default.rb +15 -13
- data/lib/lolita/configuration/tabs.rb +2 -2
- data/lib/lolita/controllers/component_helpers.rb +26 -14
- data/lib/lolita/controllers/internal_helpers.rb +14 -0
- data/lib/lolita/controllers/url_helpers.rb +47 -10
- data/lib/lolita/dbi/base.rb +50 -50
- data/lib/lolita/errors.rb +2 -2
- data/lib/lolita/hooks.rb +298 -0
- data/lib/lolita/hooks/named_hook.rb +122 -0
- data/lib/lolita/lazy_loader.rb +46 -46
- data/lib/lolita/mapping.rb +3 -2
- data/lib/lolita/navigation.rb +48 -0
- data/lib/lolita/observed_array.rb +7 -0
- data/lib/lolita/rails/routes.rb +29 -3
- data/lolita.gemspec +65 -48
- data/public/javascripts/lolita/tab.js +5 -0
- data/public/javascripts/rails.js +137 -137
- data/public/stylesheets/lolita/style.css +3 -1
- data/spec/builder_spec.rb +42 -0
- data/spec/configuration/field_spec.rb +29 -18
- data/spec/configuration/filter_spec.rb +60 -0
- data/spec/configuration/tab_spec.rb +28 -20
- data/spec/configuration/tabs_spec.rb +8 -4
- data/spec/controllers/lolita_rest_spec.rb +15 -0
- data/spec/hooks_spec.rb +191 -0
- data/spec/lolita_spec.rb +6 -4
- data/spec/navigation/tree_spec.rb +59 -0
- data/spec/rails_app/app/mongoid/post.rb +2 -0
- data/spec/rails_app/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
- data/spec/rails_app/config/application.rb +1 -0
- data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +14 -0
- data/spec/simple_spec_helper.rb +1 -0
- data/spec/spec_helper.rb +1 -2
- metadata +66 -49
- data/README.md +0 -5
- data/app/helpers/components/lolita/list_component.rb +0 -9
- data/app/views/components/lolita/field/_collection.html.erb +0 -5
- data/app/views/components/lolita/field/_date.html.erb +0 -1
- data/app/views/components/lolita/field/_datetime.html.erb +0 -1
- data/app/views/components/lolita/field/_display.html.erb +0 -6
- data/app/views/components/lolita/field/_integer.html.erb +0 -1
- data/app/views/components/lolita/field/_label.html.erb +0 -1
- data/app/views/components/lolita/field/_select.html.erb +0 -1
- data/app/views/components/lolita/field/_text.html.erb +0 -27
- data/app/views/components/lolita/list/_body.html.erb +0 -5
- data/app/views/components/lolita/list/_display.html.erb +0 -11
- data/app/views/components/lolita/list/_header.html.erb +0 -9
- data/app/views/components/lolita/list/_paginator.html.erb +0 -4
- data/app/views/components/lolita/list/_row.html.erb +0 -7
- data/app/views/components/lolita/tab/_content.html.erb +0 -1
- data/app/views/components/lolita/tab/_default.html.erb +0 -11
- data/app/views/components/lolita/tab/_display.html.erb +0 -7
- data/app/views/components/lolita/tab/_fields.html.erb +0 -7
- data/lib/lolita/configuration/field/collection.rb +0 -71
- data/lib/lolita/configuration/field/datetime.rb +0 -10
- data/lib/lolita/configuration/field/disabled.rb +0 -10
- data/lib/lolita/configuration/field/password.rb +0 -10
- data/lib/lolita/configuration/field/text.rb +0 -10
- data/lib/lolita/hooks/base.rb +0 -58
- data/lib/lolita/hooks/component.rb +0 -15
- data/lib/lolita/hooks/hooks.rb +0 -15
@@ -13,6 +13,11 @@ $(function(){
|
|
13
13
|
data:data,
|
14
14
|
success:function(data){
|
15
15
|
$("#content").html(data);
|
16
|
+
},
|
17
|
+
error:function(xhr, textStatus, errorThrown){
|
18
|
+
f = $("#flash");
|
19
|
+
f.html("<span style='color:red'>An Error occured, please contact support personel</span>");
|
20
|
+
f.slideDown("fast")
|
16
21
|
}
|
17
22
|
})
|
18
23
|
}
|
data/public/javascripts/rails.js
CHANGED
@@ -1,137 +1,137 @@
|
|
1
|
-
/**
|
2
|
-
* Unobtrusive scripting adapter for jQuery
|
3
|
-
*
|
4
|
-
* Requires jQuery 1.4.3 or later.
|
5
|
-
* https://github.com/rails/jquery-ujs
|
6
|
-
*/
|
7
|
-
|
8
|
-
(function($) {
|
9
|
-
// Triggers an event on an element and returns the event result
|
10
|
-
function fire(obj, name, data) {
|
11
|
-
var event = new $.Event(name);
|
12
|
-
obj.trigger(event, data);
|
13
|
-
return event.result !== false;
|
14
|
-
}
|
15
|
-
|
16
|
-
// Submits "remote" forms and links with ajax
|
17
|
-
function handleRemote(element) {
|
18
|
-
var method, url, data,
|
19
|
-
dataType = element.attr('data-type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
20
|
-
|
21
|
-
if (element.is('form')) {
|
22
|
-
method = element.attr('method');
|
23
|
-
url = element.attr('action');
|
24
|
-
data = element.serializeArray();
|
25
|
-
// memoized value from clicked submit button
|
26
|
-
var button = element.data('ujs:submit-button');
|
27
|
-
if (button) {
|
28
|
-
data.push(button);
|
29
|
-
element.data('ujs:submit-button', null);
|
30
|
-
}
|
31
|
-
} else {
|
32
|
-
method = element.attr('data-method');
|
33
|
-
url = element.attr('href');
|
34
|
-
data = null;
|
35
|
-
}
|
36
|
-
|
37
|
-
$.ajax({
|
38
|
-
url: url, type: method || 'GET', data: data, dataType: dataType,
|
39
|
-
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
40
|
-
beforeSend: function(xhr, settings) {
|
41
|
-
if (settings.dataType === undefined) {
|
42
|
-
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
43
|
-
}
|
44
|
-
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
45
|
-
},
|
46
|
-
success: function(data, status, xhr) {
|
47
|
-
element.trigger('ajax:success', [data, status, xhr]);
|
48
|
-
},
|
49
|
-
complete: function(xhr, status) {
|
50
|
-
element.trigger('ajax:complete', [xhr, status]);
|
51
|
-
},
|
52
|
-
error: function(xhr, status, error) {
|
53
|
-
element.trigger('ajax:error', [xhr, status, error]);
|
54
|
-
}
|
55
|
-
});
|
56
|
-
}
|
57
|
-
|
58
|
-
// Handles "data-method" on links such as:
|
59
|
-
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
60
|
-
function handleMethod(link) {
|
61
|
-
var href = link.attr('href'),
|
62
|
-
method = link.attr('data-method'),
|
63
|
-
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
64
|
-
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
65
|
-
form = $('<form method="post" action="' + href + '"></form>'),
|
66
|
-
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
67
|
-
|
68
|
-
if (csrf_param !== undefined && csrf_token !== undefined) {
|
69
|
-
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
70
|
-
}
|
71
|
-
|
72
|
-
form.hide().append(metadata_input).appendTo('body');
|
73
|
-
form.submit();
|
74
|
-
}
|
75
|
-
|
76
|
-
function disableFormElements(form) {
|
77
|
-
form.find('input[data-disable-with]').each(function() {
|
78
|
-
var input = $(this);
|
79
|
-
input.data('ujs:enable-with', input.val())
|
80
|
-
.val(input.attr('data-disable-with'))
|
81
|
-
.attr('disabled', 'disabled');
|
82
|
-
});
|
83
|
-
}
|
84
|
-
|
85
|
-
function enableFormElements(form) {
|
86
|
-
form.find('input[data-disable-with]').each(function() {
|
87
|
-
var input = $(this);
|
88
|
-
input.val(input.data('ujs:enable-with')).removeAttr('disabled');
|
89
|
-
});
|
90
|
-
}
|
91
|
-
|
92
|
-
function allowAction(element) {
|
93
|
-
var message = element.attr('data-confirm');
|
94
|
-
return !message || (fire(element, 'confirm') && confirm(message));
|
95
|
-
}
|
96
|
-
|
97
|
-
$('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
|
98
|
-
var link = $(this);
|
99
|
-
if (!allowAction(link)) return false;
|
100
|
-
|
101
|
-
if (link.attr('data-remote')) {
|
102
|
-
handleRemote(link);
|
103
|
-
return false;
|
104
|
-
} else if (link.attr('data-method')) {
|
105
|
-
handleMethod(link);
|
106
|
-
return false;
|
107
|
-
}
|
108
|
-
});
|
109
|
-
|
110
|
-
$('form').live('submit.rails', function(e) {
|
111
|
-
var form = $(this);
|
112
|
-
if (!allowAction(form)) return false;
|
113
|
-
|
114
|
-
if (form.attr('data-remote')) {
|
115
|
-
handleRemote(form);
|
116
|
-
return false;
|
117
|
-
} else {
|
118
|
-
disableFormElements(form);
|
119
|
-
}
|
120
|
-
});
|
121
|
-
|
122
|
-
$('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() {
|
123
|
-
var button = $(this);
|
124
|
-
if (!allowAction(button)) return false;
|
125
|
-
// register the pressed submit button
|
126
|
-
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
|
127
|
-
button.closest('form').data('ujs:submit-button', data);
|
128
|
-
});
|
129
|
-
|
130
|
-
$('form').live('ajax:beforeSend.rails', function(event) {
|
131
|
-
if (this == event.target) disableFormElements($(this));
|
132
|
-
});
|
133
|
-
|
134
|
-
$('form').live('ajax:complete.rails', function(event) {
|
135
|
-
if (this == event.target) enableFormElements($(this));
|
136
|
-
});
|
137
|
-
})( jQuery );
|
1
|
+
/**
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.4.3 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function($) {
|
9
|
+
// Triggers an event on an element and returns the event result
|
10
|
+
function fire(obj, name, data) {
|
11
|
+
var event = new $.Event(name);
|
12
|
+
obj.trigger(event, data);
|
13
|
+
return event.result !== false;
|
14
|
+
}
|
15
|
+
|
16
|
+
// Submits "remote" forms and links with ajax
|
17
|
+
function handleRemote(element) {
|
18
|
+
var method, url, data,
|
19
|
+
dataType = element.attr('data-type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
20
|
+
|
21
|
+
if (element.is('form')) {
|
22
|
+
method = element.attr('method');
|
23
|
+
url = element.attr('action');
|
24
|
+
data = element.serializeArray();
|
25
|
+
// memoized value from clicked submit button
|
26
|
+
var button = element.data('ujs:submit-button');
|
27
|
+
if (button) {
|
28
|
+
data.push(button);
|
29
|
+
element.data('ujs:submit-button', null);
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
method = element.attr('data-method');
|
33
|
+
url = element.attr('href');
|
34
|
+
data = null;
|
35
|
+
}
|
36
|
+
|
37
|
+
$.ajax({
|
38
|
+
url: url, type: method || 'GET', data: data, dataType: dataType,
|
39
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
40
|
+
beforeSend: function(xhr, settings) {
|
41
|
+
if (settings.dataType === undefined) {
|
42
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
43
|
+
}
|
44
|
+
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
45
|
+
},
|
46
|
+
success: function(data, status, xhr) {
|
47
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
48
|
+
},
|
49
|
+
complete: function(xhr, status) {
|
50
|
+
element.trigger('ajax:complete', [xhr, status]);
|
51
|
+
},
|
52
|
+
error: function(xhr, status, error) {
|
53
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
// Handles "data-method" on links such as:
|
59
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
60
|
+
function handleMethod(link) {
|
61
|
+
var href = link.attr('href'),
|
62
|
+
method = link.attr('data-method'),
|
63
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
64
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
65
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
66
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
67
|
+
|
68
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
69
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
70
|
+
}
|
71
|
+
|
72
|
+
form.hide().append(metadata_input).appendTo('body');
|
73
|
+
form.submit();
|
74
|
+
}
|
75
|
+
|
76
|
+
function disableFormElements(form) {
|
77
|
+
form.find('input[data-disable-with]').each(function() {
|
78
|
+
var input = $(this);
|
79
|
+
input.data('ujs:enable-with', input.val())
|
80
|
+
.val(input.attr('data-disable-with'))
|
81
|
+
.attr('disabled', 'disabled');
|
82
|
+
});
|
83
|
+
}
|
84
|
+
|
85
|
+
function enableFormElements(form) {
|
86
|
+
form.find('input[data-disable-with]').each(function() {
|
87
|
+
var input = $(this);
|
88
|
+
input.val(input.data('ujs:enable-with')).removeAttr('disabled');
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
function allowAction(element) {
|
93
|
+
var message = element.attr('data-confirm');
|
94
|
+
return !message || (fire(element, 'confirm') && confirm(message));
|
95
|
+
}
|
96
|
+
|
97
|
+
$('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
|
98
|
+
var link = $(this);
|
99
|
+
if (!allowAction(link)) return false;
|
100
|
+
|
101
|
+
if (link.attr('data-remote')) {
|
102
|
+
handleRemote(link);
|
103
|
+
return false;
|
104
|
+
} else if (link.attr('data-method')) {
|
105
|
+
handleMethod(link);
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
});
|
109
|
+
|
110
|
+
$('form').live('submit.rails', function(e) {
|
111
|
+
var form = $(this);
|
112
|
+
if (!allowAction(form)) return false;
|
113
|
+
|
114
|
+
if (form.attr('data-remote')) {
|
115
|
+
handleRemote(form);
|
116
|
+
return false;
|
117
|
+
} else {
|
118
|
+
disableFormElements(form);
|
119
|
+
}
|
120
|
+
});
|
121
|
+
|
122
|
+
$('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() {
|
123
|
+
var button = $(this);
|
124
|
+
if (!allowAction(button)) return false;
|
125
|
+
// register the pressed submit button
|
126
|
+
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
|
127
|
+
button.closest('form').data('ujs:submit-button', data);
|
128
|
+
});
|
129
|
+
|
130
|
+
$('form').live('ajax:beforeSend.rails', function(event) {
|
131
|
+
if (this == event.target) disableFormElements($(this));
|
132
|
+
});
|
133
|
+
|
134
|
+
$('form').live('ajax:complete.rails', function(event) {
|
135
|
+
if (this == event.target) enableFormElements($(this));
|
136
|
+
});
|
137
|
+
})( jQuery );
|
@@ -42,7 +42,7 @@ header nav .username {margin-right: 15px;}
|
|
42
42
|
padding: 5px 10px;
|
43
43
|
}
|
44
44
|
#main .box form .field-value { margin-top: 5px;}
|
45
|
-
#main .box form .field-value input {
|
45
|
+
#main .box form .field-value input, #main .box form .field-value textarea {
|
46
46
|
border: 1px solid #cdcdcd;
|
47
47
|
-moz-border-radius: 3px;
|
48
48
|
-webkit-border-radius: 3px;
|
@@ -65,6 +65,8 @@ header nav .username {margin-right: 15px;}
|
|
65
65
|
/* error fields and notifications */
|
66
66
|
.field_with_errors input,
|
67
67
|
.field_with_errors textarea {background: #ffe6e7;}
|
68
|
+
.inline-errors {padding-top: 3px; color:#F66; font-size: 110%;}
|
69
|
+
.errorExplanation {color:#F66; font-size: 110%; padding:25px 25px 0; background:white;}
|
68
70
|
|
69
71
|
#flash {
|
70
72
|
position: fixed;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/simple_spec_helper')
|
2
|
+
|
3
|
+
class SimpleObject
|
4
|
+
include Lolita::Builder
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Lolita::Builder do
|
8
|
+
|
9
|
+
let(:object){SimpleObject.new}
|
10
|
+
|
11
|
+
describe "#build" do
|
12
|
+
it "should return default component information when no params passed" do
|
13
|
+
info=object.build
|
14
|
+
info.first.should == :"/simple_object"
|
15
|
+
info[1].should == :display
|
16
|
+
info.last.should have_key(:simple_object)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with instance builder" do
|
20
|
+
it "should use given one" do
|
21
|
+
object.builder="custom"
|
22
|
+
info=object.build
|
23
|
+
info.first.should==:"/simple_object/custom"
|
24
|
+
info[1].should == :display
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use that what #build receive" do
|
28
|
+
object.builder="custom"
|
29
|
+
info=object.build("other")
|
30
|
+
info.first.should == :"/simple_object/other"
|
31
|
+
info[1].should == :display
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should accept empty name" do
|
36
|
+
info=object.build("",:list)
|
37
|
+
info.first.should == :"/simple_object"
|
38
|
+
info[1].should == :list
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -6,30 +6,32 @@ describe Lolita::Configuration::Field do
|
|
6
6
|
@dbi2=Lolita::DBI::Base.new(Comment)
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:field_class){Lolita::Configuration::Field::Base}
|
10
|
+
|
9
11
|
it "should create new field" do
|
10
|
-
Lolita::Configuration::Field.new(@dbi,:title)
|
12
|
+
Lolita::Configuration::Field::Base.new(@dbi,:title)
|
11
13
|
end
|
12
14
|
|
13
15
|
it "should create field when block given" do
|
14
|
-
field=
|
16
|
+
field=field_class.new(@dbi) do
|
15
17
|
name :title
|
16
18
|
end
|
17
19
|
field.name.should == :title
|
18
20
|
end
|
19
21
|
|
20
22
|
it "should create field from Hash arguments" do
|
21
|
-
field=
|
23
|
+
field=field_class.new(@dbi,:name=>:title)
|
22
24
|
field.name.should == :title
|
23
25
|
end
|
24
26
|
|
25
27
|
it "should raise error when no name specified" do
|
26
28
|
lambda{
|
27
|
-
|
29
|
+
field_class.new(@dbi)
|
28
30
|
}.should raise_error Lolita::FieldNameError
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should allow set field value" do
|
32
|
-
field=
|
34
|
+
field=field_class.new(@dbi) do
|
33
35
|
name :custom_field
|
34
36
|
value "Field value"
|
35
37
|
end
|
@@ -37,7 +39,7 @@ describe Lolita::Configuration::Field do
|
|
37
39
|
end
|
38
40
|
|
39
41
|
it "should allow set field value as block" do
|
40
|
-
field=
|
42
|
+
field=field_class.new(@dbi) do
|
41
43
|
value do |field|
|
42
44
|
field.name.to_s.upcase
|
43
45
|
end
|
@@ -54,54 +56,63 @@ describe Lolita::Configuration::Field do
|
|
54
56
|
end
|
55
57
|
|
56
58
|
it "should always set field title if not specified" do
|
57
|
-
field=
|
59
|
+
field=field_class.new(@dbi,:title)
|
58
60
|
field.title.size.should > 0
|
59
61
|
end
|
60
62
|
|
61
63
|
it "should raise error when field is nested in class that do not reference to field class" do
|
62
64
|
lambda{
|
63
|
-
field=
|
65
|
+
field=field_class.new(@dbi,:title,:nested_in=>Lolita::DBI::Base.new(Address))
|
64
66
|
}.should raise_error Lolita::ReferenceError
|
65
67
|
end
|
66
68
|
|
67
69
|
it "should detect if field is nested in" do
|
68
|
-
field=
|
70
|
+
field=field_class.new(@dbi2,:body,:nested_in=>@dbi)
|
69
71
|
field.nested?.should be_true
|
70
72
|
end
|
71
73
|
|
72
74
|
it "should detect if field is nested in given class" do
|
73
|
-
field=
|
75
|
+
field=field_class.new(@dbi2,:body,:nested_in=>@dbi)
|
74
76
|
field.nested_in?(@dbi.klass).should be_true
|
75
77
|
end
|
76
78
|
|
77
79
|
it "should return field value" do
|
78
80
|
post=Post.create!(:title=>"First post")
|
79
|
-
field=
|
81
|
+
field=field_class.new(@dbi,:title,:record=>post)
|
80
82
|
field.value.should==post.title
|
81
83
|
end
|
82
84
|
|
83
|
-
it "should
|
84
|
-
field
|
85
|
-
field.
|
85
|
+
it "should detect type and create field with specified type" do
|
86
|
+
require "rails_app/lib/lolita/configuration/field/my_custom_collection"
|
87
|
+
field=Lolita::Configuration::Field.add(@dbi,:comments, :my_custom_collection)
|
88
|
+
field.type.should == "my_custom_collection"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should fallback to string type if given type is not supported" do
|
92
|
+
field=Lolita::Configuration::Field.add(@dbi,:is_public)
|
93
|
+
field.type.should == "boolean"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should change field type for association columns if custom type is given" do
|
97
|
+
|
86
98
|
end
|
87
99
|
|
88
100
|
it "should set field title when not specified" do
|
89
|
-
field=
|
101
|
+
field=field_class.new(@dbi,:title)
|
90
102
|
field.title.should == "Title"
|
91
103
|
end
|
92
104
|
|
93
105
|
it "should allow set field that is referenced in (belongs_to) any class" do
|
94
106
|
field=Lolita::Configuration::Field.add(@dbi2,:post)
|
95
|
-
field.type.should == "
|
107
|
+
field.type.should == "array"
|
96
108
|
field.association_type.should == :one
|
97
109
|
end
|
98
110
|
|
99
111
|
it "should allow set field that references to (has_many or has_one) any class" do
|
100
112
|
field=Lolita::Configuration::Field.add(@dbi,:comments)
|
101
|
-
field.type.should == "
|
113
|
+
field.type.should == "array"
|
102
114
|
field.association_type.should == :many
|
103
115
|
end
|
104
116
|
|
105
|
-
|
106
117
|
end
|
107
118
|
|