sferik-merb-admin 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -1
- data/Rakefile +1 -2
- data/app/controllers/application.rb +2 -14
- data/app/controllers/{forms.rb → main.rb} +53 -32
- data/app/helpers/{forms_helper.rb → main_helper.rb} +1 -1
- data/app/views/{forms → main}/_big_decimal.html.erb +0 -0
- data/app/views/{forms → main}/_date.html.erb +1 -1
- data/app/views/{forms → main}/_date_time.html.erb +1 -1
- data/app/views/{forms → main}/_float.html.erb +0 -0
- data/app/views/{forms → main}/_integer.html.erb +0 -0
- data/app/views/{forms → main}/_string.html.erb +0 -0
- data/app/views/{forms → main}/_time.html.erb +1 -1
- data/app/views/{forms → main}/_true_class.html.erb +0 -0
- data/app/views/{forms → main}/delete.html.erb +2 -2
- data/app/views/{forms → main}/edit.html.erb +6 -6
- data/app/views/{forms → main}/index.html.erb +0 -0
- data/app/views/{forms → main}/list.html.erb +11 -11
- data/app/views/{forms → main}/new.html.erb +4 -4
- data/lib/merb-admin.rb +10 -9
- data/spec/controllers/main_spec.rb +29 -0
- data/spec/fixtures.rb +1 -0
- data/spec/fixtures/division_fixture.rb +17 -0
- data/spec/fixtures/league_fixture.rb +15 -0
- data/spec/fixtures/{user_fixture.rb → player_fixture.rb} +5 -3
- data/spec/fixtures/team_fixture.rb +20 -0
- data/spec/requests/main_spec.rb +422 -0
- data/spec/spec_helper.rb +0 -1
- metadata +24 -31
- data/spec/controllers/forms_spec.rb +0 -20
- data/spec/requests/forms_spec.rb +0 -204
data/README.markdown
CHANGED
@@ -14,7 +14,8 @@ At the command prompt, type:
|
|
14
14
|
|
15
15
|
In your app, add the following dependency to `config/dependencies.rb`:
|
16
16
|
|
17
|
-
dependency "sferik-merb-admin", "0.2.
|
17
|
+
dependency "sferik-merb-admin", "0.2.7", :require_as => "merb-admin"
|
18
|
+
dependency "dm-is-paginated", "0.0.1" # required for pagination
|
18
19
|
|
19
20
|
Add the following route to `config/router.rb`:
|
20
21
|
|
@@ -31,6 +32,7 @@ You can configuring the merb-admin slice in a before_app_loads block:
|
|
31
32
|
Merb::BootLoader.before_app_loads do
|
32
33
|
Merb::Slices::config[:merb_admin][:app_name] = "My App"
|
33
34
|
Merb::Slices::config[:merb_admin][:paginate] = true
|
35
|
+
Merb::Slices::config[:merb_admin][:per_page] = 100
|
34
36
|
end
|
35
37
|
|
36
38
|
## Run it
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
12
12
|
EMAIL = "sferik@gmail.com"
|
13
13
|
HOMEPAGE = "http://twitter.com/sferik"
|
14
14
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
15
|
-
GEM_VERSION = "0.2.
|
15
|
+
GEM_VERSION = "0.2.7"
|
16
16
|
|
17
17
|
spec = Gem::Specification.new do |s|
|
18
18
|
s.rubyforge_project = "merb"
|
@@ -29,7 +29,6 @@ spec = Gem::Specification.new do |s|
|
|
29
29
|
s.add_dependency("merb-slices", ">= 1.0.12")
|
30
30
|
s.add_dependency("merb_datamapper", ">= 1.0.12")
|
31
31
|
s.add_dependency("dm-core", ">= 0.9.11")
|
32
|
-
s.add_dependency("dm-is-paginated", ">= 0.0.1")
|
33
32
|
s.require_path = "lib"
|
34
33
|
s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
|
35
34
|
s.post_install_message = <<-POST_INSTALL_MESSAGE
|
@@ -1,17 +1,5 @@
|
|
1
|
-
class MerbAdmin::Application < Merb::Controller
|
2
|
-
|
3
|
-
controller_for_slice
|
4
|
-
|
5
|
-
before :set_model, :exclude => "index"
|
1
|
+
class MerbAdmin::Application < Merb::Controller
|
6
2
|
|
7
|
-
|
8
|
-
@model_name = params[:model_name].to_s.camel_case.singularize
|
9
|
-
begin
|
10
|
-
@model = eval(@model_name)
|
11
|
-
rescue StandardError
|
12
|
-
raise NotFound
|
13
|
-
end
|
14
|
-
@properties = @model.properties.to_a
|
15
|
-
end
|
3
|
+
controller_for_slice
|
16
4
|
|
17
5
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class MerbAdmin::
|
2
|
-
|
1
|
+
class MerbAdmin::Main < MerbAdmin::Application
|
2
|
+
|
3
|
+
before :find_models, :only => ['index']
|
4
|
+
before :find_model, :exclude => ['index']
|
5
|
+
before :find_object, :only => ['edit', 'update', 'delete', 'destroy']
|
3
6
|
|
4
7
|
def index
|
5
|
-
@models = DataMapper::Resource.descendants.to_a.sort{|a, b| a.to_s <=> b.to_s}
|
6
|
-
# remove DataMapperSessionStore because it's included by default
|
7
|
-
@models -= [Merb::DataMapperSessionStore] if Merb.const_defined?(:DataMapperSessionStore)
|
8
8
|
render(:layout => "dashboard")
|
9
9
|
end
|
10
10
|
|
@@ -37,40 +37,40 @@ class MerbAdmin::Forms < MerbAdmin::Application
|
|
37
37
|
options = {
|
38
38
|
:limit => 200,
|
39
39
|
}.merge(options)
|
40
|
-
@
|
40
|
+
@objects = @model.all(options).reverse
|
41
41
|
else
|
42
42
|
# monkey patch pagination
|
43
43
|
@model.class_eval("is_paginated") unless @model.respond_to?(:paginated)
|
44
44
|
@current_page = (params[:page] || 1).to_i
|
45
45
|
options = {
|
46
46
|
:page => @current_page,
|
47
|
-
:per_page =>
|
47
|
+
:per_page => MerbAdmin[:per_page],
|
48
48
|
}.merge(options)
|
49
|
-
@page_count, @
|
50
|
-
options.delete(:page)
|
51
|
-
options.delete(:per_page)
|
49
|
+
@page_count, @objects = @model.paginated(options)
|
52
50
|
end
|
51
|
+
options.delete(:page)
|
52
|
+
options.delete(:per_page)
|
53
|
+
options.delete(:offset)
|
54
|
+
options.delete(:limit)
|
53
55
|
@record_count = @model.count(options)
|
54
56
|
render(:layout => "list")
|
55
57
|
end
|
56
58
|
|
57
59
|
def new
|
58
|
-
@
|
60
|
+
@object = @model.new
|
59
61
|
render(:layout => "form")
|
60
62
|
end
|
61
63
|
|
62
|
-
def edit
|
63
|
-
@instance = @model.get(id)
|
64
|
-
raise NotFound unless @instance
|
64
|
+
def edit
|
65
65
|
render(:layout => "form")
|
66
66
|
end
|
67
67
|
|
68
68
|
def create
|
69
|
-
|
70
|
-
@
|
71
|
-
if @
|
69
|
+
object = eval("params[:#{@model_name.snake_case}]") || {}
|
70
|
+
@object = @model.new(object)
|
71
|
+
if @object.save
|
72
72
|
if params[:_continue]
|
73
|
-
redirect(slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => @
|
73
|
+
redirect(slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => @object.id), :message => {:notice => "#{@model_name} was successfully created"})
|
74
74
|
elsif params[:_add_another]
|
75
75
|
redirect(slice_url(:admin_new, :model_name => @model_name.snake_case), :message => {:notice => "#{@model_name} was successfully created"})
|
76
76
|
else
|
@@ -82,13 +82,11 @@ class MerbAdmin::Forms < MerbAdmin::Application
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def update
|
86
|
-
|
87
|
-
|
88
|
-
raise NotFound unless @instance
|
89
|
-
if @instance.update_attributes(instance)
|
85
|
+
def update
|
86
|
+
object = eval("params[:#{@model_name.snake_case}]") || {}
|
87
|
+
if @object.update_attributes(object)
|
90
88
|
if params[:_continue]
|
91
|
-
redirect(slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => @
|
89
|
+
redirect(slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => @object.id), :message => {:notice => "#{@model_name} was successfully updated"})
|
92
90
|
elsif params[:_add_another]
|
93
91
|
redirect(slice_url(:admin_new, :model_name => @model_name.snake_case), :message => {:notice => "#{@model_name} was successfully updated"})
|
94
92
|
else
|
@@ -100,20 +98,43 @@ class MerbAdmin::Forms < MerbAdmin::Application
|
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
103
|
-
def delete
|
104
|
-
@instance = @model.get(id)
|
105
|
-
raise NotFound unless @instance
|
101
|
+
def delete
|
106
102
|
render(:layout => "form")
|
107
103
|
end
|
108
104
|
|
109
|
-
def destroy
|
110
|
-
|
111
|
-
raise NotFound unless @instance
|
112
|
-
if @instance.destroy
|
105
|
+
def destroy
|
106
|
+
if @object.destroy
|
113
107
|
redirect(slice_url(:admin_list, :model_name => @model_name.snake_case), :message => {:notice => "#{@model_name} was successfully destroyed"})
|
114
108
|
else
|
115
|
-
raise
|
109
|
+
raise BadRequest
|
116
110
|
end
|
117
111
|
end
|
118
112
|
|
113
|
+
private
|
114
|
+
|
115
|
+
def find_models
|
116
|
+
@models = DataMapper::Resource.descendants.to_a.sort{|a, b| a.to_s <=> b.to_s}
|
117
|
+
# remove DataMapperSessionStore because it's included by default
|
118
|
+
@models -= [Merb::DataMapperSessionStore] if Merb.const_defined?(:DataMapperSessionStore)
|
119
|
+
end
|
120
|
+
|
121
|
+
def find_model
|
122
|
+
@model_name = params[:model_name].camel_case.singularize
|
123
|
+
begin
|
124
|
+
@model = eval(@model_name)
|
125
|
+
rescue StandardError
|
126
|
+
raise NotFound
|
127
|
+
end
|
128
|
+
find_properties
|
129
|
+
end
|
130
|
+
|
131
|
+
def find_properties
|
132
|
+
@properties = @model.properties.to_a
|
133
|
+
end
|
134
|
+
|
135
|
+
def find_object
|
136
|
+
@object = @model.get(params[:id])
|
137
|
+
raise NotFound unless @object
|
138
|
+
end
|
139
|
+
|
119
140
|
end
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% value = eval("@
|
1
|
+
<% value = eval("@object.#{property.field}") %>
|
2
2
|
<div>
|
3
3
|
<%= text_field(property.name, :class => "vDateField", :label => property.field.capitalize.gsub('_', ' '), :value => value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : nil) %>
|
4
4
|
<p class="help">
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% value = eval("@
|
1
|
+
<% value = eval("@object.#{property.field}") %>
|
2
2
|
<div>
|
3
3
|
<%= text_field(property.name, :class => "vDateField", :label => property.field.capitalize.gsub('_', ' '), :value => value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d %H:%M:%S") : nil) %>
|
4
4
|
<p class="help">
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% value = eval("@
|
1
|
+
<% value = eval("@object.#{property.field}") %>
|
2
2
|
<div>
|
3
3
|
<%= text_field(property.name, :class => "vTimeField", :label => property.field.capitalize.gsub('_', ' '), :value => value.respond_to?(:strftime) ? value.strftime("%H:%M:%S") : nil) %>
|
4
4
|
<p class="help">
|
File without changes
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<p>Are you sure you want to delete the <%= @model_name.snake_case.gsub('_', ' ') %>? All of the following related items will be deleted:</p>
|
2
2
|
<ul>
|
3
3
|
<li>
|
4
|
-
<%= link_to(@model_name, slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => @
|
4
|
+
<%= link_to(@model_name, slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => @object.id))%>
|
5
5
|
</li>
|
6
6
|
</ul>
|
7
|
-
<%= form_for(@
|
7
|
+
<%= form_for(@object, :action => slice_url(:admin_destroy, :model_name => @model_name.snake_case, :id => @object.id), :method => :delete) do %>
|
8
8
|
<div>
|
9
9
|
<%= submit "Yes, I'm sure" %>
|
10
10
|
</div>
|
@@ -1,18 +1,18 @@
|
|
1
1
|
<div id="content-main">
|
2
2
|
<ul class="object-tools">
|
3
3
|
<li>
|
4
|
-
<%= link_to("View on site", "/#{@model_name.snake_case}/#{@
|
4
|
+
<%= link_to("View on site", "/#{@model_name.snake_case}/#{@object.id}", :target => "_blank", :class => "viewsitelink") %>
|
5
5
|
</li>
|
6
6
|
</ul>
|
7
|
-
<%= form_for(@
|
7
|
+
<%= form_for(@object, :action => slice_url(:admin_update, :model_name => @model_name.snake_case, :id => @object.id)) do %>
|
8
8
|
<div>
|
9
9
|
<fieldset class="module aligned">
|
10
10
|
<% @properties.each do |property| %>
|
11
11
|
<% next if [:id, :created_at, :created_on, :updated_at, :updated_on].include?(property.name) %>
|
12
|
-
<div class="<%= @
|
13
|
-
<% if @
|
12
|
+
<div class="<%= @object.errors[property.name] ? "form-row errors" : "form-row"%>">
|
13
|
+
<% if @object.errors[property.name] %>
|
14
14
|
<ul class="errorlist">
|
15
|
-
<% @
|
15
|
+
<% @object.errors[property.name].each do |error| %>
|
16
16
|
<li><%= error %></li>
|
17
17
|
<% end %>
|
18
18
|
</ul>
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<div class="submit-row" >
|
25
25
|
<%= submit "Save", :class => "default", :name => "_save" %>
|
26
26
|
<p class="deletelink-box">
|
27
|
-
<%= link_to("Delete", slice_url(:admin_delete, :model_name => @model_name.snake_case, :id => @
|
27
|
+
<%= link_to("Delete", slice_url(:admin_delete, :model_name => @model_name.snake_case, :id => @object.id), :class => "deletelink") %>
|
28
28
|
</p>
|
29
29
|
<%= submit "Save and add another", :name => "_add_another" %>
|
30
30
|
<%= submit "Save and continue editing", :name => "_continue" %>
|
File without changes
|
@@ -66,39 +66,39 @@
|
|
66
66
|
</tr>
|
67
67
|
</thead>
|
68
68
|
<tbody>
|
69
|
-
<% @
|
69
|
+
<% @objects.each_with_index do |object, index| %>
|
70
70
|
<tr class="row<%= index % 2 == 0 ? '1' : '2' %>">
|
71
71
|
<% @properties.each do |property| %>
|
72
72
|
<td>
|
73
|
-
<a href="<%= slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => eval("
|
73
|
+
<a href="<%= slice_url(:admin_edit, :model_name => @model_name.snake_case, :id => eval("object.id")) %>">
|
74
74
|
<% case property.primitive.to_s %>
|
75
75
|
<% when "TrueClass" %>
|
76
|
-
<% if eval("
|
76
|
+
<% if eval("object.#{property.field}") == true %>
|
77
77
|
<img alt="True" src="<%= image_path("icon-yes.gif") %>"/>
|
78
78
|
<% else %>
|
79
79
|
<img alt="False" src="<%= image_path("icon-no.gif") %>"/>
|
80
80
|
<% end %>
|
81
81
|
<% when "DateTime" %>
|
82
|
-
<% value = eval("
|
82
|
+
<% value = eval("object.#{property.field}") %>
|
83
83
|
<%= value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y, %I:%M%p") : nil %>
|
84
84
|
<% when "Date" %>
|
85
|
-
<% value = eval("
|
85
|
+
<% value = eval("object.#{property.field}") %>
|
86
86
|
<%= value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y") : nil %>
|
87
87
|
<% when "Time" %>
|
88
|
-
<% value = eval("
|
88
|
+
<% value = eval("object.#{property.field}") %>
|
89
89
|
<%= value.respond_to?(:strftime) ? value.strftime("%I:%M%p") : nil %>
|
90
90
|
<% when "Integer" %>
|
91
91
|
<% if property.type.respond_to?(:flag_map) #Enum or Flag type %>
|
92
|
-
<%= eval("
|
92
|
+
<%= eval("object.#{property.field}").to_s.capitalize.gsub('_', ' ') %>
|
93
93
|
<% else %>
|
94
|
-
<%= eval("
|
94
|
+
<%= eval("object.#{property.field}") %>
|
95
95
|
<% end %>
|
96
96
|
<% when "BigDecimal" %>
|
97
|
-
<%= eval("
|
97
|
+
<%= eval("object.#{property.field}") %>
|
98
98
|
<% when "Float" %>
|
99
|
-
<%= eval("
|
99
|
+
<%= eval("object.#{property.field}") %>
|
100
100
|
<% when "String" %>
|
101
|
-
<%= eval("
|
101
|
+
<%= eval("object.#{property.field}").to_s.truncate(50) %>
|
102
102
|
<% end %>
|
103
103
|
</a>
|
104
104
|
</td>
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<div id="content-main">
|
2
|
-
<%= form_for(@
|
2
|
+
<%= form_for(@object, :action => slice_url(:admin_create, :model_name => @model_name.snake_case)) do %>
|
3
3
|
<div>
|
4
4
|
<fieldset class="module aligned">
|
5
5
|
<% @properties.each do |property| %>
|
6
6
|
<% next if [:id, :created_at, :created_on, :updated_at, :updated_on].include?(property.name) %>
|
7
|
-
<div class="<%= @
|
8
|
-
<% if @
|
7
|
+
<div class="<%= @object.errors[property.name] ? "form-row errors" : "form-row"%>">
|
8
|
+
<% if @object.errors[property.name] %>
|
9
9
|
<ul class="errorlist">
|
10
|
-
<% @
|
10
|
+
<% @object.errors[property.name].each do |error| %>
|
11
11
|
<li><%= error %></li>
|
12
12
|
<% end %>
|
13
13
|
</ul>
|
data/lib/merb-admin.rb
CHANGED
@@ -16,13 +16,14 @@ if defined?(Merb::Plugins)
|
|
16
16
|
# :layout - the layout to use; defaults to :merb-admin
|
17
17
|
# :mirror - which path component types to use on copy operations; defaults to all
|
18
18
|
Merb::Slices::config[:merb_admin][:layout] ||= :merb_admin
|
19
|
+
Merb::Slices::config[:merb_admin][:per_page] ||= 100
|
19
20
|
|
20
21
|
# All Slice code is expected to be namespaced inside a module
|
21
22
|
module MerbAdmin
|
22
23
|
|
23
24
|
# Slice metadata
|
24
25
|
self.description = "MerbAdmin is a merb slice that uses your DataMapper models to provide an easy-to-use, Django-style interface for content managers."
|
25
|
-
self.version = "0.2.
|
26
|
+
self.version = "0.2.7"
|
26
27
|
self.author = "Erik Michaels-Ober"
|
27
28
|
|
28
29
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
@@ -44,35 +45,35 @@ if defined?(Merb::Plugins)
|
|
44
45
|
|
45
46
|
def self.setup_router(scope)
|
46
47
|
scope.match("/admin(/index)", :method => :get).
|
47
|
-
to(:controller => "
|
48
|
+
to(:controller => "main", :action => "index").
|
48
49
|
name(:admin_dashboard)
|
49
50
|
|
50
51
|
scope.match("/admin/:model_name(/index)", :method => :get).
|
51
|
-
to(:controller => "
|
52
|
+
to(:controller => "main", :action => "list").
|
52
53
|
name(:admin_list)
|
53
54
|
|
54
55
|
scope.match("/admin/:model_name/new", :method => :get).
|
55
|
-
to(:controller => "
|
56
|
+
to(:controller => "main", :action => "new").
|
56
57
|
name(:admin_new)
|
57
58
|
|
58
59
|
scope.match("/admin/:model_name/:id/edit", :method => :get).
|
59
|
-
to(:controller => "
|
60
|
+
to(:controller => "main", :action => "edit").
|
60
61
|
name(:admin_edit)
|
61
62
|
|
62
63
|
scope.match("/admin/:model_name", :method => :post).
|
63
|
-
to(:controller => "
|
64
|
+
to(:controller => "main", :action => "create").
|
64
65
|
name(:admin_create)
|
65
66
|
|
66
67
|
scope.match("/admin/:model_name/:id", :method => :put).
|
67
|
-
to(:controller => "
|
68
|
+
to(:controller => "main", :action => "update").
|
68
69
|
name(:admin_update)
|
69
70
|
|
70
71
|
scope.match("/admin/:model_name/:id/delete", :method => :get).
|
71
|
-
to(:controller => "
|
72
|
+
to(:controller => "main", :action => "delete").
|
72
73
|
name(:admin_delete)
|
73
74
|
|
74
75
|
scope.match("/admin/:model_name/:id(.:format)", :method => :delete).
|
75
|
-
to(:controller => "
|
76
|
+
to(:controller => "main", :action => "destroy").
|
76
77
|
name(:admin_destroy)
|
77
78
|
end
|
78
79
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe MerbAdmin::Main do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
mount_slice
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have helper methods for dealing with public paths" do
|
10
|
+
@controller = dispatch_to(MerbAdmin::Main, :index)
|
11
|
+
|
12
|
+
@controller.public_path_for(:image).should == "/slices/merb-admin/images"
|
13
|
+
@controller.public_path_for(:javascript).should == "/slices/merb-admin/javascripts"
|
14
|
+
@controller.public_path_for(:stylesheet).should == "/slices/merb-admin/stylesheets"
|
15
|
+
|
16
|
+
@controller.image_path.should == "/slices/merb-admin/images"
|
17
|
+
@controller.javascript_path.should == "/slices/merb-admin/javascripts"
|
18
|
+
@controller.stylesheet_path.should == "/slices/merb-admin/stylesheets"
|
19
|
+
|
20
|
+
@controller.app_path_for(:image).should == "#{Merb.root}/public/slices/merb-admin/images"
|
21
|
+
@controller.app_path_for(:javascript).should == "#{Merb.root}/public/slices/merb-admin/javascripts"
|
22
|
+
@controller.app_path_for(:stylesheet).should == "#{Merb.root}/public/slices/merb-admin/stylesheets"
|
23
|
+
|
24
|
+
@controller.slice_path_for(:image).should == "#{Merb.root}/public/images"
|
25
|
+
@controller.slice_path_for(:javascript).should == "#{Merb.root}/public/javascripts"
|
26
|
+
@controller.slice_path_for(:stylesheet).should == "#{Merb.root}/public/stylesheets"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/fixtures.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Division
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
property :id, Serial
|
5
|
+
property :created_at, DateTime
|
6
|
+
property :updated_at, DateTime
|
7
|
+
property :league_id, Integer, :nullable => false, :index => true
|
8
|
+
property :name, String, :nullable => false, :index => true
|
9
|
+
|
10
|
+
belongs_to :league
|
11
|
+
has n, :teams
|
12
|
+
end
|
13
|
+
|
14
|
+
Division.fixture {{
|
15
|
+
:league_id => /\d{1,2}/.gen,
|
16
|
+
:name => /\w{5,10}/.gen.capitalize,
|
17
|
+
}}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class League
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
property :id, Serial
|
5
|
+
property :created_at, DateTime
|
6
|
+
property :updated_at, DateTime
|
7
|
+
property :name, String, :nullable => false, :index => true
|
8
|
+
|
9
|
+
has n, :divisions
|
10
|
+
has n, :teams
|
11
|
+
end
|
12
|
+
|
13
|
+
League.fixture {{
|
14
|
+
:name => /\w{5,10}/.gen.capitalize,
|
15
|
+
}}
|
@@ -6,7 +6,8 @@ class Player
|
|
6
6
|
property :updated_at, DateTime
|
7
7
|
property :deleted_at, ParanoidDateTime
|
8
8
|
property :team_id, Integer, :nullable => false, :index => true
|
9
|
-
property :
|
9
|
+
property :number, Integer, :nullable => false
|
10
|
+
property :name, String, :length => 100, :nullable => false
|
10
11
|
property :position, Flag[:pitcher, :catcher, :first, :second, :third, :shortstop, :left, :center, :right]
|
11
12
|
property :sex, Enum[:male, :female]
|
12
13
|
property :batting_average, Float, :default => 0.0, :precision => 4, :scale => 3
|
@@ -16,11 +17,12 @@ class Player
|
|
16
17
|
property :wake_at, Time
|
17
18
|
property :notes, Text
|
18
19
|
|
19
|
-
|
20
|
+
belongs_to :team
|
20
21
|
end
|
21
22
|
|
22
23
|
Player.fixture {{
|
24
|
+
:team_id => /\d{1,2}/.gen,
|
25
|
+
:number => /\d{1,2}/.gen,
|
23
26
|
:name => "#{/\w{3,10}/.gen.capitalize} #{/\w{5,10}/.gen.capitalize}",
|
24
27
|
:sex => Player.properties[:sex].type.flag_map.values[rand(Player.properties[:sex].type.flag_map.length)],
|
25
|
-
:team_id => 1,
|
26
28
|
}}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Team
|
2
|
+
include DataMapper::Resource
|
3
|
+
|
4
|
+
property :id, Serial
|
5
|
+
property :created_at, DateTime
|
6
|
+
property :updated_at, DateTime
|
7
|
+
property :league_id, Integer, :nullable => false, :index => true
|
8
|
+
property :division_id, Integer, :nullable => false, :index => true
|
9
|
+
property :name, String, :nullable => false, :index => true
|
10
|
+
|
11
|
+
belongs_to :league
|
12
|
+
belongs_to :division
|
13
|
+
has n, :players
|
14
|
+
end
|
15
|
+
|
16
|
+
Team.fixture {{
|
17
|
+
:league_id => /\d{1,2}/.gen,
|
18
|
+
:division_id => /\d{1,2}/.gen,
|
19
|
+
:name => /\w{5,10}/.gen.capitalize,
|
20
|
+
}}
|
@@ -0,0 +1,422 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
|
+
|
3
|
+
given "an object exists" do
|
4
|
+
@player = Player.gen
|
5
|
+
end
|
6
|
+
|
7
|
+
given "two players exist" do
|
8
|
+
@players = 2.times{Player.gen}
|
9
|
+
end
|
10
|
+
|
11
|
+
given "twenty players exist" do
|
12
|
+
@players = 20.times{Player.gen}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "MerbAdmin" do
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
mount_slice
|
19
|
+
Player.all.destroy!
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "dashboard" do
|
23
|
+
before(:each) do
|
24
|
+
@response = request(url(:admin_dashboard))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should respond sucessfully" do
|
28
|
+
@response.should be_successful
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should should contain \"Site administration\"" do
|
32
|
+
@response.body.should contain("Site administration")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "list" do
|
37
|
+
before(:each) do
|
38
|
+
@response = request(url(:admin_list, :model_name => "player"))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should respond sucessfully" do
|
42
|
+
@response.should be_successful
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should contain \"Select model to edit\"" do
|
46
|
+
@response.body.should contain("Select #{"player".gsub('_', ' ')} to edit")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "list with query" do
|
51
|
+
before(:each) do
|
52
|
+
Player.gen(:name => "Jackie Robinson")
|
53
|
+
Player.gen(:name => "Sandy Koufax")
|
54
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:query => "Jackie Robinson"})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should respond sucessfully" do
|
58
|
+
@response.should be_successful
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should contain matching results" do
|
62
|
+
@response.body.should contain("Jackie Robinson")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not contain non-matching results" do
|
66
|
+
@response.body.should_not contain("Sandy Koufax")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "list with sort" do
|
71
|
+
before(:each) do
|
72
|
+
Player.gen(:name => "Jackie Robinson")
|
73
|
+
Player.gen(:name => "Sandy Koufax")
|
74
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:sort => :name})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should respond sucessfully" do
|
78
|
+
@response.should be_successful
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be ordered correctly" do
|
82
|
+
@response.body.should contain(/Sandy Koufax.*Jackie Robinson/m)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "list with reverse sort" do
|
87
|
+
before(:each) do
|
88
|
+
Player.gen(:name => "Jackie Robinson")
|
89
|
+
Player.gen(:name => "Sandy Koufax")
|
90
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:sort => :name, :sort_reverse => true})
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should respond sucessfully" do
|
94
|
+
@response.should be_successful
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be ordered correctly" do
|
98
|
+
@response.body.should contain(/Jackie Robinson.*Sandy Koufax/m)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "list with boolean filter" do
|
103
|
+
before(:each) do
|
104
|
+
Player.gen(:name => "Jackie Robinson", :retired => true)
|
105
|
+
Player.gen(:name => "David Wright", :retired => false)
|
106
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:filter => {:retired => true}})
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should respond sucessfully" do
|
110
|
+
@response.should be_successful
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should contain matching results" do
|
114
|
+
@response.body.should contain("Jackie Robinson")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not contain non-matching results" do
|
118
|
+
@response.body.should_not contain("David Wright")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "list with enum filter" do
|
123
|
+
before(:each) do
|
124
|
+
Player.gen(:name => "Jackie Robinson", :sex => :male)
|
125
|
+
Player.gen(:name => "Dottie Hinson", :sex => :female)
|
126
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:filter => {:sex => :male}})
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should respond sucessfully" do
|
130
|
+
@response.should be_successful
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should contain matching results" do
|
134
|
+
@response.body.should contain("Jackie Robinson")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not contain non-matching results" do
|
138
|
+
@response.body.should_not contain("Dottie Hinson")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "list with 2 players", :given => "two players exist" do
|
143
|
+
before(:each) do
|
144
|
+
MerbAdmin[:paginate] = true
|
145
|
+
MerbAdmin[:per_page] = 1
|
146
|
+
@response = request(url(:admin_list, :model_name => "player"))
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should respond sucessfully" do
|
150
|
+
@response.should be_successful
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should contain \"2 results\"" do
|
154
|
+
@response.body.should contain("2 #{"player".gsub('_', ' ').pluralize}")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "list with 2 players, show all", :given => "two players exist" do
|
159
|
+
before(:each) do
|
160
|
+
MerbAdmin[:paginate] = true
|
161
|
+
MerbAdmin[:per_page] = 1
|
162
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:all => true})
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should respond sucessfully" do
|
166
|
+
@response.should be_successful
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should contain \"2 results\"" do
|
170
|
+
@response.body.should contain("2 #{"player".gsub('_', ' ').pluralize}")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "list with 20 players", :given => "twenty players exist" do
|
175
|
+
before(:each) do
|
176
|
+
MerbAdmin[:paginate] = true
|
177
|
+
MerbAdmin[:per_page] = 1
|
178
|
+
@response = request(url(:admin_list, :model_name => "player"))
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should respond sucessfully" do
|
182
|
+
@response.should be_successful
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should contain \"20 results\"" do
|
186
|
+
@response.body.should contain("20 #{"player".gsub('_', ' ').pluralize}")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "list with 20 players, page 8", :given => "twenty players exist" do
|
191
|
+
before(:each) do
|
192
|
+
MerbAdmin[:paginate] = true
|
193
|
+
MerbAdmin[:per_page] = 1
|
194
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:page => 8})
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should respond sucessfully" do
|
198
|
+
@response.should be_successful
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should contain \"20 results\"" do
|
202
|
+
@response.body.should contain("20 #{"player".gsub('_', ' ').pluralize}")
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "list with 20 players, page 17", :given => "twenty players exist" do
|
207
|
+
before(:each) do
|
208
|
+
MerbAdmin[:paginate] = true
|
209
|
+
MerbAdmin[:per_page] = 1
|
210
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:page => 17})
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should respond sucessfully" do
|
214
|
+
@response.should be_successful
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should contain \"20 results\"" do
|
218
|
+
@response.body.should contain("20 #{"player".gsub('_', ' ').pluralize}")
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "new" do
|
223
|
+
before(:each) do
|
224
|
+
@response = request(url(:admin_new, :model_name => "player"))
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should respond sucessfully" do
|
228
|
+
@response.should be_successful
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should contain \"New model\"" do
|
232
|
+
@response.body.should contain("New #{"player".gsub('_', ' ')}")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "edit", :given => "an object exists" do
|
237
|
+
before(:each) do
|
238
|
+
@response = request(url(:admin_edit, :model_name => "player", :id => @player.id))
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should respond sucessfully" do
|
242
|
+
@response.should be_successful
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should contain \"Edit model\"" do
|
246
|
+
@response.body.should contain("Edit #{"player".gsub('_', ' ')}")
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "edit with missing object" do
|
251
|
+
before(:each) do
|
252
|
+
@response = request(url(:admin_edit, :model_name => "player", :id => 1))
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should raise NotFound" do
|
256
|
+
@response.status.should == 404
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "create" do
|
261
|
+
before(:each) do
|
262
|
+
@response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}})
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should redirect to list" do
|
266
|
+
@response.should redirect_to(url(:admin_list, :model_name => "player"))
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should create a new player" do
|
270
|
+
Player.first.should_not be_nil
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "create with invalid object" do
|
275
|
+
before(:each) do
|
276
|
+
@response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {}})
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should have an error message" do
|
280
|
+
@response.body.should contain("Player failed to be created")
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "create and edit" do
|
285
|
+
before(:each) do
|
286
|
+
@response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}, :_continue => true})
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should redirect to edit" do
|
290
|
+
@response.should redirect_to(url(:admin_edit, :model_name => "player", :id => Player.first.id))
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should create a new player" do
|
294
|
+
Player.first.should_not be_nil
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe "create and add another" do
|
299
|
+
before(:each) do
|
300
|
+
@response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}, :_add_another => true})
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should redirect to new" do
|
304
|
+
@response.should redirect_to(url(:admin_new, :model_name => "player"))
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should create a new player" do
|
308
|
+
Player.first.should_not be_nil
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "update", :given => "an object exists" do
|
313
|
+
before(:each) do
|
314
|
+
@response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}})
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should redirect to list" do
|
318
|
+
@response.should redirect_to(url(:admin_list, :model_name => "player"))
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should update an object that already exists" do
|
322
|
+
Player.first(:id => @player.id).name.should eql("Jackie Robinson")
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "update with invalid object", :given => "an object exists" do
|
327
|
+
before(:each) do
|
328
|
+
@response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:number => nil}})
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should have an error message" do
|
332
|
+
@response.body.should contain("Player failed to be updated")
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
describe "update with missing object" do
|
337
|
+
before(:each) do
|
338
|
+
@response = request(url(:admin_update, :model_name => "player", :id => 1), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}})
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should raise NotFound" do
|
342
|
+
@response.status.should == 404
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
describe "update and edit", :given => "an object exists" do
|
347
|
+
before(:each) do
|
348
|
+
@response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}, :_continue => true})
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should redirect to edit" do
|
352
|
+
@response.should redirect_to(url(:admin_edit, :model_name => "player", :id => @player.id))
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should update an object that already exists" do
|
356
|
+
Player.first(:id => @player.id).name.should eql("Jackie Robinson")
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
describe "update and add another", :given => "an object exists" do
|
361
|
+
before(:each) do
|
362
|
+
@response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}, :_add_another => true})
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should redirect to new" do
|
366
|
+
@response.should redirect_to(url(:admin_new, :model_name => "player"))
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should update an object that already exists" do
|
370
|
+
Player.first(:id => @player.id).name.should eql("Jackie Robinson")
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe "delete", :given => "an object exists" do
|
375
|
+
before(:each) do
|
376
|
+
@response = request(url(:admin_delete, :model_name => "player", :id => @player.id))
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should respond sucessfully" do
|
380
|
+
@response.should be_successful
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should contain \"Delete model\"" do
|
384
|
+
@response.body.should contain("Delete #{"player".gsub('_', ' ')}")
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "delete with missing object" do
|
389
|
+
before(:each) do
|
390
|
+
@response = request(url(:admin_delete, :model_name => "player", :id => 1))
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should raise NotFound" do
|
394
|
+
@response.status.should == 404
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
describe "destroy", :given => "an object exists" do
|
399
|
+
before(:each) do
|
400
|
+
@response = request(url(:admin_destroy, :model_name => "player", :id => @player.id), :method => "delete")
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should redirect to list" do
|
404
|
+
@response.should redirect_to(url(:admin_list, :model_name => "player"))
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should destroy an object" do
|
408
|
+
Player.first(:id => @player.id).should be_nil
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
describe "destroy with missing object" do
|
413
|
+
before(:each) do
|
414
|
+
@response = request(url(:admin_destroy, :model_name => "player", :id => 1), :method => "delete")
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should raise NotFound" do
|
418
|
+
@response.status.should == 404
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sferik-merb-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Michaels-Ober
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,16 +42,6 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.9.11
|
44
44
|
version:
|
45
|
-
- !ruby/object:Gem::Dependency
|
46
|
-
name: dm-is-paginated
|
47
|
-
type: :runtime
|
48
|
-
version_requirement:
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.0.1
|
54
|
-
version:
|
55
45
|
description: MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.
|
56
46
|
email: sferik@gmail.com
|
57
47
|
executables: []
|
@@ -71,39 +61,42 @@ files:
|
|
71
61
|
- lib/merb-admin/spectasks.rb
|
72
62
|
- lib/merb-admin.rb
|
73
63
|
- spec/controllers
|
74
|
-
- spec/controllers/
|
64
|
+
- spec/controllers/main_spec.rb
|
75
65
|
- spec/fixtures
|
76
|
-
- spec/fixtures/
|
66
|
+
- spec/fixtures/division_fixture.rb
|
67
|
+
- spec/fixtures/league_fixture.rb
|
68
|
+
- spec/fixtures/player_fixture.rb
|
69
|
+
- spec/fixtures/team_fixture.rb
|
77
70
|
- spec/fixtures.rb
|
78
71
|
- spec/requests
|
79
|
-
- spec/requests/
|
72
|
+
- spec/requests/main_spec.rb
|
80
73
|
- spec/spec_helper.rb
|
81
74
|
- app/controllers
|
82
75
|
- app/controllers/application.rb
|
83
|
-
- app/controllers/
|
76
|
+
- app/controllers/main.rb
|
84
77
|
- app/helpers
|
85
78
|
- app/helpers/application_helper.rb
|
86
|
-
- app/helpers/
|
79
|
+
- app/helpers/main_helper.rb
|
87
80
|
- app/views
|
88
|
-
- app/views/forms
|
89
|
-
- app/views/forms/_big_decimal.html.erb
|
90
|
-
- app/views/forms/_date.html.erb
|
91
|
-
- app/views/forms/_date_time.html.erb
|
92
|
-
- app/views/forms/_float.html.erb
|
93
|
-
- app/views/forms/_integer.html.erb
|
94
|
-
- app/views/forms/_string.html.erb
|
95
|
-
- app/views/forms/_time.html.erb
|
96
|
-
- app/views/forms/_true_class.html.erb
|
97
|
-
- app/views/forms/delete.html.erb
|
98
|
-
- app/views/forms/edit.html.erb
|
99
|
-
- app/views/forms/index.html.erb
|
100
|
-
- app/views/forms/list.html.erb
|
101
|
-
- app/views/forms/new.html.erb
|
102
81
|
- app/views/layout
|
103
82
|
- app/views/layout/_message.html.erb
|
104
83
|
- app/views/layout/dashboard.html.erb
|
105
84
|
- app/views/layout/form.html.erb
|
106
85
|
- app/views/layout/list.html.erb
|
86
|
+
- app/views/main
|
87
|
+
- app/views/main/_big_decimal.html.erb
|
88
|
+
- app/views/main/_date.html.erb
|
89
|
+
- app/views/main/_date_time.html.erb
|
90
|
+
- app/views/main/_float.html.erb
|
91
|
+
- app/views/main/_integer.html.erb
|
92
|
+
- app/views/main/_string.html.erb
|
93
|
+
- app/views/main/_time.html.erb
|
94
|
+
- app/views/main/_true_class.html.erb
|
95
|
+
- app/views/main/delete.html.erb
|
96
|
+
- app/views/main/edit.html.erb
|
97
|
+
- app/views/main/index.html.erb
|
98
|
+
- app/views/main/list.html.erb
|
99
|
+
- app/views/main/new.html.erb
|
107
100
|
- public/images
|
108
101
|
- public/images/arrow-down.gif
|
109
102
|
- public/images/arrow-up.gif
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe MerbAdmin::Forms do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
mount_slice
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should have helper methods for dealing with public paths" do
|
10
|
-
@controller = dispatch_to(MerbAdmin::Forms, :index)
|
11
|
-
@controller.public_path_for(:image).should == "/slices/merb-admin/images"
|
12
|
-
@controller.public_path_for(:javascript).should == "/slices/merb-admin/javascripts"
|
13
|
-
@controller.public_path_for(:stylesheet).should == "/slices/merb-admin/stylesheets"
|
14
|
-
|
15
|
-
@controller.image_path.should == "/slices/merb-admin/images"
|
16
|
-
@controller.javascript_path.should == "/slices/merb-admin/javascripts"
|
17
|
-
@controller.stylesheet_path.should == "/slices/merb-admin/stylesheets"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/requests/forms_spec.rb
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
|
-
|
3
|
-
given "a model exists" do
|
4
|
-
@model_name = 'Player'
|
5
|
-
@model = eval(@model_name)
|
6
|
-
@model.all.destroy!
|
7
|
-
end
|
8
|
-
|
9
|
-
given "an instance exists" do
|
10
|
-
@model_name = 'Player'
|
11
|
-
@model = eval(@model_name)
|
12
|
-
@model.all.destroy!
|
13
|
-
@instance = @model.gen
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "MerbAdmin" do
|
17
|
-
|
18
|
-
before(:each) do
|
19
|
-
mount_slice
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "dashboard" do
|
23
|
-
before(:each) do
|
24
|
-
@response = request(url(:admin_dashboard))
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should respond sucessfully" do
|
28
|
-
@response.should be_successful
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should should contain \"Site administration\"" do
|
32
|
-
@response.body.should contain("Site administration")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "list", :given => "a model exists" do
|
37
|
-
before(:each) do
|
38
|
-
@response = request(url(:admin_list, :model_name => @model_name.snake_case))
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should respond sucessfully" do
|
42
|
-
@response.should be_successful
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should contain \"Select model to edit\"" do
|
46
|
-
@response.body.should contain("Select #{@model_name.snake_case.gsub('_', ' ')} to edit")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "list with query", :given => "a model exists" do
|
51
|
-
before(:each) do
|
52
|
-
@response = request(url(:admin_list, :model_name => @model_name.snake_case), :params => {:query => "Jackie Robinson"})
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should respond sucessfully" do
|
56
|
-
@response.should be_successful
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should contain \"results\"" do
|
60
|
-
@response.body.should contain("results")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "new", :given => "a model exists" do
|
65
|
-
before(:each) do
|
66
|
-
@response = request(url(:admin_new, :model_name => @model_name.snake_case))
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should respond sucessfully" do
|
70
|
-
@response.should be_successful
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should contain \"New model\"" do
|
74
|
-
@response.body.should contain("New #{@model_name.snake_case.gsub('_', ' ')}")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "edit", :given => "an instance exists" do
|
79
|
-
before(:each) do
|
80
|
-
@response = request(url(:admin_edit, :model_name => @model_name.snake_case, :id => @instance.id))
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should respond sucessfully" do
|
84
|
-
@response.should be_successful
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should contain \"Edit model\"" do
|
88
|
-
@response.body.should contain("Edit #{@model_name.snake_case.gsub('_', ' ')}")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "create", :given => "a model exists" do
|
93
|
-
before(:each) do
|
94
|
-
@response = request(url(:admin_create, :model_name => @model_name.snake_case), :method => "post", :params => {:player => {:name => "Jackie Robinson", :team_id => 1, :sex => :male}})
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should create a new instance" do
|
98
|
-
@model.first.should_not be_nil
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should redirect to list" do
|
102
|
-
@response.should redirect_to(url(:admin_list, :model_name => @model_name.snake_case))
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "create and edit", :given => "a model exists" do
|
107
|
-
before(:each) do
|
108
|
-
@response = request(url(:admin_create, :model_name => @model_name.snake_case), :method => "post", :params => {:player => {:name => "Jackie Robinson", :team_id => 1, :sex => :male}, :_continue => true})
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should create a new instance" do
|
112
|
-
@model.first.should_not be_nil
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should redirect to edit" do
|
116
|
-
@response.should redirect_to(url(:admin_edit, :model_name => @model_name.snake_case, :id => @model.first.id))
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "create and add another", :given => "a model exists" do
|
121
|
-
before(:each) do
|
122
|
-
@response = request(url(:admin_create, :model_name => @model_name.snake_case), :method => "post", :params => {:player => {:name => "Jackie Robinson", :team_id => 1, :sex => :male}, :_add_another => true})
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should create a new instance" do
|
126
|
-
@model.first.should_not be_nil
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should redirect to new" do
|
130
|
-
@response.should redirect_to(url(:admin_new, :model_name => @model_name.snake_case))
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "update", :given => "an instance exists" do
|
135
|
-
before(:each) do
|
136
|
-
@response = request(url(:admin_update, :model_name => @model_name.snake_case, :id => @instance.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :team_id => 1, :sex => :male}})
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should update an instance that already exists" do
|
140
|
-
@model.first(:id => @instance.id).name.should eql("Jackie Robinson")
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should redirect to list" do
|
144
|
-
@response.should redirect_to(url(:admin_list, :model_name => @model_name.snake_case))
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "update and edit", :given => "an instance exists" do
|
149
|
-
before(:each) do
|
150
|
-
@response = request(url(:admin_update, :model_name => @model_name.snake_case, :id => @instance.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :team_id => 1, :sex => :male}, :_continue => true})
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should update an instance that already exists" do
|
154
|
-
@model.first(:id => @instance.id).name.should eql("Jackie Robinson")
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should redirect to edit" do
|
158
|
-
@response.should redirect_to(url(:admin_edit, :model_name => @model_name.snake_case, :id => @instance.id))
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe "update and add another", :given => "an instance exists" do
|
163
|
-
before(:each) do
|
164
|
-
@response = request(url(:admin_update, :model_name => @model_name.snake_case, :id => @instance.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :team_id => 1, :sex => :male}, :_add_another => true})
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should update an instance that already exists" do
|
168
|
-
@model.first(:id => @instance.id).name.should eql("Jackie Robinson")
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should redirect to new" do
|
172
|
-
@response.should redirect_to(url(:admin_new, :model_name => @model_name.snake_case))
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "delete", :given => "an instance exists" do
|
177
|
-
before(:each) do
|
178
|
-
@response = request(url(:admin_delete, :model_name => @model_name.snake_case, :id => @instance.id))
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should respond sucessfully" do
|
182
|
-
@response.should be_successful
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should contain \"Delete model\"" do
|
186
|
-
@response.body.should contain("Delete #{@model_name.snake_case.gsub('_', ' ')}")
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
describe "destroy", :given => "an instance exists" do
|
191
|
-
before(:each) do
|
192
|
-
@response = request(url(:admin_update, :model_name => @model_name.snake_case, :id => @instance.id), :method => "delete")
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should destroy an instance" do
|
196
|
-
@model.first(:id => @instance.id).should be_nil
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should redirect to list" do
|
200
|
-
@response.should redirect_to(url(:admin_list, :model_name => @model_name.snake_case))
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|