merb-admin 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -2
- data/Rakefile +1 -1
- data/app/controllers/main.rb +7 -7
- data/app/views/layout/form.html.erb +2 -2
- data/app/views/layout/list.html.erb +1 -1
- data/app/views/main/delete.html.erb +2 -2
- data/app/views/main/edit.html.erb +5 -11
- data/app/views/main/index.html.erb +4 -4
- data/app/views/main/list.html.erb +10 -12
- data/app/views/main/new.html.erb +4 -10
- data/lib/merb-admin.rb +9 -9
- data/schema/migrations/004_create_players_migration.rb +1 -4
- data/schema/migrations/005_create_teams_migration.rb +9 -0
- data/spec/models/activerecord/division.rb +1 -2
- data/spec/models/activerecord/draft.rb +5 -10
- data/spec/models/activerecord/player.rb +2 -4
- data/spec/models/activerecord/team.rb +7 -4
- data/spec/models/datamapper/player.rb +4 -4
- data/spec/models/datamapper/team.rb +8 -0
- data/spec/requests/main_spec.rb +100 -73
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/README.markdown
CHANGED
@@ -16,11 +16,11 @@ At the command prompt, type:
|
|
16
16
|
|
17
17
|
In your app, add the following dependency to `config/dependencies.rb`:
|
18
18
|
|
19
|
-
dependency "merb-admin", "0.4.
|
19
|
+
dependency "merb-admin", "0.4.9"
|
20
20
|
|
21
21
|
Add the following route to `config/router.rb`:
|
22
22
|
|
23
|
-
add_slice(:merb_admin, :
|
23
|
+
add_slice(:merb_admin, :path_prefix => "admin")
|
24
24
|
|
25
25
|
Then, run the following rake task:
|
26
26
|
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
9
9
|
EMAIL = "sferik@gmail.com"
|
10
10
|
HOMEPAGE = "http://twitter.com/sferik"
|
11
11
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
12
|
-
GEM_VERSION = "0.4.
|
12
|
+
GEM_VERSION = "0.4.9"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.rubyforge_project = "merb"
|
data/app/controllers/main.rb
CHANGED
@@ -60,11 +60,11 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
60
60
|
@object = @abstract_model.new(object)
|
61
61
|
if @object.save && has_one_associations.each{|association, id| update_has_one_association(association, id)} && has_many_associations.each{|association, ids| update_has_many_association(association, ids)}
|
62
62
|
if params[:_continue]
|
63
|
-
redirect(url(:
|
63
|
+
redirect(url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => @object.id), :message => {:notice => "#{@abstract_model.pretty_name} was successfully created"})
|
64
64
|
elsif params[:_add_another]
|
65
|
-
redirect(url(:
|
65
|
+
redirect(url(:merb_admin_new, :model_name => @abstract_model.singular_name), :message => {:notice => "#{@abstract_model.pretty_name} was successfully created"})
|
66
66
|
else
|
67
|
-
redirect(url(:
|
67
|
+
redirect(url(:merb_admin_list, :model_name => @abstract_model.singular_name), :message => {:notice => "#{@abstract_model.pretty_name} was successfully created"})
|
68
68
|
end
|
69
69
|
else
|
70
70
|
message[:error] = "#{@abstract_model.pretty_name} failed to be created"
|
@@ -82,11 +82,11 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
82
82
|
has_many_associations = @abstract_model.has_many_associations.map{|association| [association, (params[:associations] || {}).delete(association[:name])]}
|
83
83
|
if @object.update_attributes(object) && has_one_associations.each{|association, id| update_has_one_association(association, id)} && has_many_associations.each{|association, ids| update_has_many_association(association, ids)}
|
84
84
|
if params[:_continue]
|
85
|
-
redirect(url(:
|
85
|
+
redirect(url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => @object.id), :message => {:notice => "#{@abstract_model.pretty_name} was successfully updated"})
|
86
86
|
elsif params[:_add_another]
|
87
|
-
redirect(url(:
|
87
|
+
redirect(url(:merb_admin_new, :model_name => @abstract_model.singular_name), :message => {:notice => "#{@abstract_model.pretty_name} was successfully updated"})
|
88
88
|
else
|
89
|
-
redirect(url(:
|
89
|
+
redirect(url(:merb_admin_list, :model_name => @abstract_model.singular_name), :message => {:notice => "#{@abstract_model.pretty_name} was successfully updated"})
|
90
90
|
end
|
91
91
|
else
|
92
92
|
message[:error] = "#{@abstract_model.pretty_name} failed to be updated"
|
@@ -100,7 +100,7 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
100
100
|
|
101
101
|
def destroy
|
102
102
|
if @object.destroy
|
103
|
-
redirect(url(:
|
103
|
+
redirect(url(:merb_admin_list, :model_name => @abstract_model.singular_name), :message => {:notice => "#{@abstract_model.pretty_name} was successfully destroyed"})
|
104
104
|
else
|
105
105
|
raise BadRequest
|
106
106
|
end
|
@@ -31,8 +31,8 @@
|
|
31
31
|
</div>
|
32
32
|
</div>
|
33
33
|
<div class="breadcrumbs">
|
34
|
-
<%= link_to("Home", url(:
|
35
|
-
<%= link_to(@abstract_model.plural_name.to_s.capitalize, url(:
|
34
|
+
<%= link_to("Home", url(:merb_admin_dashboard)) %> ›
|
35
|
+
<%= link_to(@abstract_model.plural_name.to_s.capitalize, url(:merb_admin_list, :model_name => @abstract_model.singular_name)) %> ›
|
36
36
|
<%= page_name %>
|
37
37
|
</div>
|
38
38
|
<%= partial('layout/message', :message => message) unless message.blank? -%>
|
@@ -26,7 +26,7 @@
|
|
26
26
|
</div>
|
27
27
|
</div>
|
28
28
|
<div class="breadcrumbs">
|
29
|
-
<%= link_to("Home", url(:
|
29
|
+
<%= link_to("Home", url(:merb_admin_dashboard)) %> ›
|
30
30
|
<%= @abstract_model.plural_name.to_s.capitalize %>
|
31
31
|
</div>
|
32
32
|
<%= partial('layout/message', :message => message) unless message.blank? -%>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<p>Are you sure you want to delete the <%= @abstract_model.pretty_name.downcase %>? All of the following related items will be deleted:</p>
|
2
2
|
<ul>
|
3
3
|
<li>
|
4
|
-
<%= link_to(@model_name, url(:
|
4
|
+
<%= link_to(@model_name, url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => @object.id))%>
|
5
5
|
</li>
|
6
6
|
</ul>
|
7
|
-
<%= form_for(@object, :action => url(:
|
7
|
+
<%= form_for(@object, :action => url(:merb_admin_destroy, :model_name => @abstract_model.singular_name, :id => @object.id), :method => :delete) do %>
|
8
8
|
<div>
|
9
9
|
<%= submit "Yes, I'm sure" %>
|
10
10
|
</div>
|
@@ -1,20 +1,14 @@
|
|
1
1
|
<div id="content-main">
|
2
|
-
<%= form_for(@object, :action => url(:
|
2
|
+
<%= form_for(@object, :action => url(:merb_admin_update, :model_name => @abstract_model.singular_name, :id => @object.id)) do %>
|
3
3
|
<div>
|
4
4
|
<%= partial('properties', :properties => @properties) -%>
|
5
|
-
|
6
|
-
<%= partial('
|
7
|
-
|
8
|
-
<% @abstract_model.has_one_associations.each do |association| %>
|
9
|
-
<%= partial('has_one', :association => association) -%>
|
10
|
-
<% end %>
|
11
|
-
<% @abstract_model.has_many_associations.each do |association| %>
|
12
|
-
<%= partial('has_many', :association => association) -%>
|
13
|
-
<% end %>
|
5
|
+
<%= partial('belongs_to', :with => @abstract_model.belongs_to_associations, :as => :association) -%>
|
6
|
+
<%= partial('has_one', :with => @abstract_model.has_one_associations, :as => :association) -%>
|
7
|
+
<%= partial('has_many', :with => @abstract_model.has_many_associations, :as => :association) -%>
|
14
8
|
<div class="submit-row" >
|
15
9
|
<%= submit "Save", :class => "default", :name => "_save" %>
|
16
10
|
<p class="deletelink-box">
|
17
|
-
<%= link_to("Delete", url(:
|
11
|
+
<%= link_to("Delete", url(:merb_admin_delete, :model_name => @abstract_model.singular_name, :id => @object.id), :class => "deletelink") %>
|
18
12
|
</p>
|
19
13
|
<%= submit "Save and add another", :name => "_add_another" %>
|
20
14
|
<%= submit "Save and continue editing", :name => "_continue" %>
|
@@ -2,18 +2,18 @@
|
|
2
2
|
<div class="module">
|
3
3
|
<table summary="Models available in the application.">
|
4
4
|
<caption>
|
5
|
-
<%= link_to("Models", url(:
|
5
|
+
<%= link_to("Models", url(:merb_admin_dashboard), :class => "section") %>
|
6
6
|
</caption>
|
7
7
|
<% @abstract_models.each do |abstract_model| %>
|
8
8
|
<tr>
|
9
9
|
<th scope="row">
|
10
|
-
<%= link_to(abstract_model.plural_name.to_s.capitalize, url(:
|
10
|
+
<%= link_to(abstract_model.plural_name.to_s.capitalize, url(:merb_admin_list, :model_name => abstract_model.singular_name)) %>
|
11
11
|
</th>
|
12
12
|
<td>
|
13
|
-
<%= link_to("Add", url(:
|
13
|
+
<%= link_to("Add", url(:merb_admin_new, :model_name => abstract_model.singular_name), :class => "addlink") %>
|
14
14
|
</td>
|
15
15
|
<td>
|
16
|
-
<%= link_to("Edit", url(:
|
16
|
+
<%= link_to("Edit", url(:merb_admin_list, :model_name => abstract_model.singular_name), :class => "changelink") %>
|
17
17
|
</td>
|
18
18
|
</tr>
|
19
19
|
<% end %>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<div id="content-main">
|
9
9
|
<ul class="object-tools">
|
10
10
|
<li>
|
11
|
-
<%= link_to("Add #{@abstract_model.pretty_name.downcase}", url(:
|
11
|
+
<%= link_to("Add #{@abstract_model.pretty_name.downcase}", url(:merb_admin_new, :model_name => @abstract_model.singular_name), :class => "addlink") %>
|
12
12
|
</li>
|
13
13
|
</ul>
|
14
14
|
<div class="module filtered" id="changelist">
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<input type="text" size="40" name="query" value="<%= query %>" id="searchbar" />
|
20
20
|
<input type="submit" value="Search" />
|
21
21
|
<% if query || filter %>
|
22
|
-
|
22
|
+
<span class="small quiet"><%= @record_count %> <%= @record_count == 1 ? "result" : "results" %> (<%= link_to("#{@abstract_model.count} total", "?") %>)</span>
|
23
23
|
<% end %>
|
24
24
|
<% if filter %>
|
25
25
|
<% filter.each do |name, value| %>
|
@@ -40,13 +40,13 @@
|
|
40
40
|
<h3>By <%= property_pretty_name %></h3>
|
41
41
|
<ul>
|
42
42
|
<li class="<%= filter.nil? || filter[property_name].blank? ? "selected" : nil %>">
|
43
|
-
|
43
|
+
<%= link_to("All", "?" + Merb::Parse.params_to_query_string(params.merge(:filter => (filter || {}).reject{|key, value| key.to_sym == property_name}))) %>
|
44
44
|
</li>
|
45
45
|
<li class="<%= filter && filter[property_name] == "true" ? "selected" : nil %>">
|
46
|
-
|
46
|
+
<%= link_to("Yes", "?" + Merb::Parse.params_to_query_string(params.merge(:filter => (filter || {}).merge({property_name => "true"})))) %>
|
47
47
|
</li>
|
48
48
|
<li class="<%= filter && filter[property_name] == "false" ? "selected" : nil %>">
|
49
|
-
|
49
|
+
<%= link_to("No", "?" + Merb::Parse.params_to_query_string(params.merge(:filter => (filter || {}).merge({property_name => "false"})))) %>
|
50
50
|
</li>
|
51
51
|
</ul>
|
52
52
|
<% end %>
|
@@ -59,19 +59,17 @@
|
|
59
59
|
<% property_name = property[:name] %>
|
60
60
|
<% property_pretty_name = property[:pretty_name] %>
|
61
61
|
<th class="<%= sort == property_name.to_s ? sort_reverse ? 'sorted descending' : 'sorted ascending' : nil %>">
|
62
|
-
|
62
|
+
<%= link_to(property_pretty_name, "?" + Merb::Parse.params_to_query_string(params.merge(:sort => property_name).reject{|key, value| key.to_sym == :sort_reverse}.merge(sort == property_name.to_s && sort_reverse != "true" ? {:sort_reverse => "true"} : {}))) %>
|
63
63
|
</th>
|
64
64
|
<% end %>
|
65
65
|
</tr>
|
66
66
|
</thead>
|
67
67
|
<tbody>
|
68
68
|
<% @objects.each_with_index do |object, index| %>
|
69
|
-
<tr class="row<%= index % 2 == 0 ?
|
69
|
+
<tr class="row<%= index % 2 == 0 ? "1" : "2" %>">
|
70
70
|
<% @properties.each do |property| %>
|
71
71
|
<td>
|
72
|
-
|
73
|
-
<%= object_property(object, property) %>
|
74
|
-
</a>
|
72
|
+
<%= link_to(object_property(object, property), url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => object.id)) %>
|
75
73
|
</td>
|
76
74
|
<% end %>
|
77
75
|
</tr>
|
@@ -80,11 +78,11 @@
|
|
80
78
|
</table>
|
81
79
|
<p class="paginator">
|
82
80
|
<% if @page_count.to_i > 1 %>
|
83
|
-
<%= paginate(@current_page, @page_count, :url =>
|
81
|
+
<%= paginate(@current_page, @page_count, :url => "?" + Merb::Parse.params_to_query_string(params)) %>
|
84
82
|
<% end %>
|
85
83
|
<%= @record_count %> <%= @record_count == 1 ? @abstract_model.pretty_name.downcase : @abstract_model.pretty_name.downcase.pluralize %>
|
86
84
|
<% if @page_count.to_i == 2 %>
|
87
|
-
<%= link_to("Show all",
|
85
|
+
<%= link_to("Show all", "?" + Merb::Parse.params_to_query_string(params.merge(:all => true)), :class => "showall") %>
|
88
86
|
<% end %>
|
89
87
|
</p>
|
90
88
|
</div>
|
data/app/views/main/new.html.erb
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
<div id="content-main">
|
2
|
-
<%= form_for(@object, :action => url(:
|
2
|
+
<%= form_for(@object, :action => url(:merb_admin_create, :model_name => @abstract_model.singular_name)) do %>
|
3
3
|
<div>
|
4
4
|
<%= partial('properties', :properties => @properties) -%>
|
5
|
-
|
6
|
-
<%= partial('
|
7
|
-
|
8
|
-
<% @abstract_model.has_one_associations.each do |association| %>
|
9
|
-
<%= partial('has_one', :association => association) -%>
|
10
|
-
<% end %>
|
11
|
-
<% @abstract_model.has_many_associations.each do |association| %>
|
12
|
-
<%= partial('has_many', :association => association) -%>
|
13
|
-
<% end %>
|
5
|
+
<%= partial('belongs_to', :with => @abstract_model.belongs_to_associations, :as => :association) -%>
|
6
|
+
<%= partial('has_one', :with => @abstract_model.has_one_associations, :as => :association) -%>
|
7
|
+
<%= partial('has_many', :with => @abstract_model.has_many_associations, :as => :association) -%>
|
14
8
|
<div class="submit-row" >
|
15
9
|
<%= submit "Save", :class => "default", :name => "_save" %>
|
16
10
|
<%= submit "Save and add another", :name => "_add_another" %>
|
data/lib/merb-admin.rb
CHANGED
@@ -23,7 +23,7 @@ if defined?(Merb::Plugins)
|
|
23
23
|
|
24
24
|
# Slice metadata
|
25
25
|
self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
26
|
-
self.version = "0.4.
|
26
|
+
self.version = "0.4.9"
|
27
27
|
self.author = "Erik Michaels-Ober"
|
28
28
|
|
29
29
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
@@ -46,35 +46,35 @@ if defined?(Merb::Plugins)
|
|
46
46
|
def self.setup_router(scope)
|
47
47
|
scope.match("/", :method => :get).
|
48
48
|
to(:controller => "main", :action => "index").
|
49
|
-
name(:
|
49
|
+
name(:dashboard)
|
50
50
|
|
51
51
|
scope.match("/:model_name", :method => :get).
|
52
52
|
to(:controller => "main", :action => "list").
|
53
|
-
name(:
|
53
|
+
name(:list)
|
54
54
|
|
55
55
|
scope.match("/:model_name/new", :method => :get).
|
56
56
|
to(:controller => "main", :action => "new").
|
57
|
-
name(:
|
57
|
+
name(:new)
|
58
58
|
|
59
59
|
scope.match("/:model_name/:id/edit", :method => :get).
|
60
60
|
to(:controller => "main", :action => "edit").
|
61
|
-
name(:
|
61
|
+
name(:edit)
|
62
62
|
|
63
63
|
scope.match("/:model_name", :method => :post).
|
64
64
|
to(:controller => "main", :action => "create").
|
65
|
-
name(:
|
65
|
+
name(:create)
|
66
66
|
|
67
67
|
scope.match("/:model_name/:id", :method => :put).
|
68
68
|
to(:controller => "main", :action => "update").
|
69
|
-
name(:
|
69
|
+
name(:update)
|
70
70
|
|
71
71
|
scope.match("/:model_name/:id/delete", :method => :get).
|
72
72
|
to(:controller => "main", :action => "delete").
|
73
|
-
name(:
|
73
|
+
name(:delete)
|
74
74
|
|
75
75
|
scope.match("/:model_name/:id(.:format)", :method => :delete).
|
76
76
|
to(:controller => "main", :action => "destroy").
|
77
|
-
name(:
|
77
|
+
name(:destroy)
|
78
78
|
end
|
79
79
|
|
80
80
|
end
|
@@ -6,15 +6,12 @@ class CreatePlayersMigration < ActiveRecord::Migration
|
|
6
6
|
t.integer :team_id
|
7
7
|
t.string :name, :limit => 100, :null => false
|
8
8
|
t.string :position, :limit => 50
|
9
|
-
t.integer :number
|
10
|
-
t.float :batting_average, :default => 0.0
|
9
|
+
t.integer :number, :null => false
|
11
10
|
t.boolean :retired, :default => false
|
12
11
|
t.boolean :injured, :default => false
|
13
12
|
t.date :born_on
|
14
|
-
t.timestamp :wake_at
|
15
13
|
t.text :notes
|
16
14
|
end
|
17
|
-
add_index :players, :team_id
|
18
15
|
end
|
19
16
|
|
20
17
|
def self.down
|
@@ -5,10 +5,19 @@ class CreateTeamsMigration < ActiveRecord::Migration
|
|
5
5
|
t.integer :league_id
|
6
6
|
t.integer :division_id
|
7
7
|
t.string :name, :limit => 50, :null => false
|
8
|
+
t.string :logo_image_url, :limit => 255
|
9
|
+
t.string :manager, :limit => 100, :null => false
|
10
|
+
t.string :ballpark, :limit => 100
|
11
|
+
t.string :mascot, :limit => 100
|
12
|
+
t.integer :founded
|
13
|
+
t.integer :wins
|
14
|
+
t.integer :losses
|
15
|
+
t.float :win_percentage
|
8
16
|
end
|
9
17
|
add_index :teams, :division_id
|
10
18
|
add_index :teams, :league_id
|
11
19
|
add_index :teams, :name
|
20
|
+
add_index :teams, :manager
|
12
21
|
end
|
13
22
|
|
14
23
|
def self.down
|
@@ -1,15 +1,10 @@
|
|
1
1
|
class Draft < ActiveRecord::Base
|
2
|
-
|
3
|
-
validates_numericality_of :
|
4
|
-
validates_presence_of :team_id
|
5
|
-
validates_numericality_of :team_id
|
2
|
+
validates_numericality_of :player_id, :only_integer => true
|
3
|
+
validates_numericality_of :team_id, :only_integer => true
|
6
4
|
validates_presence_of :date
|
7
|
-
|
8
|
-
validates_numericality_of :
|
9
|
-
|
10
|
-
validates_numericality_of :pick
|
11
|
-
validates_presence_of :overall
|
12
|
-
validates_numericality_of :overall
|
5
|
+
validates_numericality_of :round, :only_integer => true
|
6
|
+
validates_numericality_of :pick, :only_integer => true
|
7
|
+
validates_numericality_of :overall, :only_integer => true
|
13
8
|
|
14
9
|
belongs_to :team
|
15
10
|
belongs_to :player
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class Player < ActiveRecord::Base
|
2
|
-
validates_presence_of :team_id
|
3
|
-
validates_numericality_of :team_id
|
4
2
|
validates_presence_of :name
|
5
|
-
|
6
|
-
|
3
|
+
validates_numericality_of :number, :only_integer => true
|
4
|
+
validates_uniqueness_of :number, :scope => :team_id, :message => "There is already a player with that number on this team"
|
7
5
|
|
8
6
|
belongs_to :team
|
9
7
|
has_one :draft
|
@@ -1,9 +1,12 @@
|
|
1
1
|
class Team < ActiveRecord::Base
|
2
|
-
|
3
|
-
validates_numericality_of :
|
4
|
-
validates_presence_of :division_id
|
5
|
-
validates_numericality_of :division_id
|
2
|
+
validates_numericality_of :league_id, :only_integer => true
|
3
|
+
validates_numericality_of :division_id, :only_integer => true
|
6
4
|
validates_presence_of :name
|
5
|
+
validates_presence_of :manager
|
6
|
+
validates_numericality_of :founded, :only_integer => true
|
7
|
+
validates_numericality_of :wins, :only_integer => true
|
8
|
+
validates_numericality_of :losses, :only_integer => true
|
9
|
+
validates_numericality_of :win_percentage
|
7
10
|
|
8
11
|
belongs_to :league
|
9
12
|
belongs_to :division
|
@@ -5,17 +5,17 @@ class Player
|
|
5
5
|
property :created_at, DateTime
|
6
6
|
property :updated_at, DateTime
|
7
7
|
property :deleted_at, ParanoidDateTime
|
8
|
-
property :team_id, Integer
|
9
|
-
property :name, String, :length => 100, :nullable => false
|
8
|
+
property :team_id, Integer
|
9
|
+
property :name, String, :length => 100, :nullable => false, :index => true
|
10
10
|
property :position, String
|
11
11
|
property :number, Integer, :nullable => false
|
12
|
-
property :batting_average, Float, :default => 0.0, :precision => 4, :scale => 3
|
13
12
|
property :retired, Boolean, :default => false
|
14
13
|
property :injured, Boolean, :default => false
|
15
14
|
property :born_on, Date
|
16
|
-
property :wake_at, Time
|
17
15
|
property :notes, Text
|
18
16
|
|
17
|
+
validates_is_unique :number, :scope => :team_id, :message => "There is already a player with that number on this team"
|
18
|
+
|
19
19
|
belongs_to :team
|
20
20
|
has 1, :draft
|
21
21
|
end
|
@@ -7,6 +7,14 @@ class Team
|
|
7
7
|
property :league_id, Integer, :nullable => false, :index => true
|
8
8
|
property :division_id, Integer, :nullable => false, :index => true
|
9
9
|
property :name, String, :nullable => false, :index => true
|
10
|
+
property :logo_image_url, String, :length => 255
|
11
|
+
property :manager, String, :length => 100, :nullable => false, :index => true
|
12
|
+
property :ballpark, String, :length => 100
|
13
|
+
property :mascot, String, :length => 100
|
14
|
+
property :founded, Integer, :nullable => false
|
15
|
+
property :wins, Integer, :nullable => false
|
16
|
+
property :losses, Integer, :nullable => false
|
17
|
+
property :win_percentage, Float, :nullable => false, :precision => 4, :scale => 3
|
10
18
|
|
11
19
|
belongs_to :league
|
12
20
|
belongs_to :division
|
data/spec/requests/main_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
2
|
|
3
3
|
given "a player exists" do
|
4
|
-
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
4
|
+
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
|
5
5
|
end
|
6
6
|
|
7
7
|
given "a draft exists" do
|
@@ -11,27 +11,27 @@ end
|
|
11
11
|
given "two players exist" do
|
12
12
|
@players = []
|
13
13
|
2.times do |i|
|
14
|
-
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
14
|
+
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => i + 1, :name => "Player #{i + 1}")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
given "three teams exist" do
|
19
19
|
@teams = []
|
20
20
|
3.times do |i|
|
21
|
-
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i}")
|
21
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i + 1}", :manager => "Manager #{i + 1}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => "%.3f" % (wins.to_f / 162))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
given "a player exists and a draft exists" do
|
26
|
-
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
26
|
+
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
|
27
27
|
@draft = MerbAdmin::AbstractModel.new("Draft").create(:player_id => rand(99999), :team_id => rand(99999), :date => Date.today, :round => rand(50), :pick => rand(30), :overall => rand(1500))
|
28
28
|
end
|
29
29
|
|
30
30
|
given "a player exists and three teams exist" do
|
31
|
-
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
31
|
+
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
|
32
32
|
@teams = []
|
33
33
|
3.times do |i|
|
34
|
-
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i}")
|
34
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i + 1}", :manager => "Manager #{i + 1}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => "%.3f" % (wins.to_f / 162))
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,19 +39,18 @@ given "a league exists and three teams exist" do
|
|
39
39
|
@league = League.create(:name => "League 1")
|
40
40
|
@teams = []
|
41
41
|
3.times do |i|
|
42
|
-
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i}")
|
42
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i + 1}", :manager => "Manager #{i + 1}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => "%.3f" % (wins.to_f / 162))
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
given "twenty players exist" do
|
47
47
|
@players = []
|
48
48
|
20.times do |i|
|
49
|
-
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
49
|
+
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => i + 1, :name => "Player #{i + 1}")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "MerbAdmin" do
|
54
|
-
|
55
54
|
before(:each) do
|
56
55
|
mount_slice
|
57
56
|
MerbAdmin::AbstractModel.new("Division").destroy_all!
|
@@ -63,7 +62,7 @@ describe "MerbAdmin" do
|
|
63
62
|
|
64
63
|
describe "dashboard" do
|
65
64
|
before(:each) do
|
66
|
-
@response = request(url(:
|
65
|
+
@response = request(url(:merb_admin_dashboard))
|
67
66
|
end
|
68
67
|
|
69
68
|
it "should respond sucessfully" do
|
@@ -77,7 +76,7 @@ describe "MerbAdmin" do
|
|
77
76
|
|
78
77
|
describe "list" do
|
79
78
|
before(:each) do
|
80
|
-
@response = request(url(:
|
79
|
+
@response = request(url(:merb_admin_list, :model_name => "player"))
|
81
80
|
end
|
82
81
|
|
83
82
|
it "should respond sucessfully" do
|
@@ -87,13 +86,21 @@ describe "MerbAdmin" do
|
|
87
86
|
it "should show \"Select model to edit\"" do
|
88
87
|
@response.body.should contain("Select player to edit")
|
89
88
|
end
|
89
|
+
|
90
|
+
it "should show filters" do
|
91
|
+
@response.body.should contain(/Filter\n\s*By Retired\n\s*All\n\s*Yes\n\s*No\n\s*By Injured\n\s*All\n\s*Yes\n\s*No/)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should show column headers" do
|
95
|
+
@response.body.should contain(/Id\n\s*Created at\n\s*Updated at\n\s*Deleted at\n\s*Team\n\s*Name\n\s*Position\n\s*Number\n\s*Retired\n\s*Injured\n\s*Born on\n\s*Notes/)
|
96
|
+
end
|
90
97
|
end
|
91
98
|
|
92
99
|
describe "list with sort" do
|
93
100
|
before(:each) do
|
94
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "
|
95
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "
|
96
|
-
@response = request(url(:
|
101
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
|
102
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
|
103
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:sort => "name"})
|
97
104
|
end
|
98
105
|
|
99
106
|
it "should respond sucessfully" do
|
@@ -107,9 +114,9 @@ describe "MerbAdmin" do
|
|
107
114
|
|
108
115
|
describe "list with reverse sort" do
|
109
116
|
before(:each) do
|
110
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "
|
111
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "
|
112
|
-
@response = request(url(:
|
117
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
|
118
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
|
119
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:sort => "name", :sort_reverse => "true"})
|
113
120
|
end
|
114
121
|
|
115
122
|
it "should respond sucessfully" do
|
@@ -123,9 +130,9 @@ describe "MerbAdmin" do
|
|
123
130
|
|
124
131
|
describe "list with query" do
|
125
132
|
before(:each) do
|
126
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "
|
127
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "
|
128
|
-
@response = request(url(:
|
133
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
|
134
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
|
135
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:query => "Jackie Robinson"})
|
129
136
|
end
|
130
137
|
|
131
138
|
it "should respond sucessfully" do
|
@@ -143,11 +150,11 @@ describe "MerbAdmin" do
|
|
143
150
|
|
144
151
|
describe "list with query and boolean filter" do
|
145
152
|
before(:each) do
|
146
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "
|
147
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "
|
148
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "
|
149
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "
|
150
|
-
@response = request(url(:
|
153
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher", :retired => true, :injured => true)
|
154
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman", :retired => true, :injured => false)
|
155
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :retired => false, :injured => true)
|
156
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
|
157
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:query => "Sandy Koufax", :filter => {:injured => "true"}})
|
151
158
|
end
|
152
159
|
|
153
160
|
it "should respond sucessfully" do
|
@@ -168,9 +175,9 @@ describe "MerbAdmin" do
|
|
168
175
|
|
169
176
|
describe "list with boolean filter" do
|
170
177
|
before(:each) do
|
171
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "
|
172
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "
|
173
|
-
@response = request(url(:
|
178
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :injured => true)
|
179
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :injured => false)
|
180
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:filter => {:injured => "true"}})
|
174
181
|
end
|
175
182
|
|
176
183
|
it "should respond sucessfully" do
|
@@ -188,11 +195,11 @@ describe "MerbAdmin" do
|
|
188
195
|
|
189
196
|
describe "list with boolean filters" do
|
190
197
|
before(:each) do
|
191
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "
|
192
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "
|
193
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "
|
194
|
-
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "
|
195
|
-
@response = request(url(:
|
198
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher", :retired => true, :injured => true)
|
199
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman", :retired => true, :injured => false)
|
200
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :retired => false, :injured => true)
|
201
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
|
202
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:filter => {:retired => "true", :injured => "true"}})
|
196
203
|
end
|
197
204
|
|
198
205
|
it "should respond sucessfully" do
|
@@ -213,7 +220,7 @@ describe "MerbAdmin" do
|
|
213
220
|
before(:each) do
|
214
221
|
MerbAdmin[:paginate] = true
|
215
222
|
MerbAdmin[:per_page] = 1
|
216
|
-
@response = request(url(:
|
223
|
+
@response = request(url(:merb_admin_list, :model_name => "player"))
|
217
224
|
end
|
218
225
|
|
219
226
|
it "should respond sucessfully" do
|
@@ -229,7 +236,7 @@ describe "MerbAdmin" do
|
|
229
236
|
before(:each) do
|
230
237
|
MerbAdmin[:paginate] = true
|
231
238
|
MerbAdmin[:per_page] = 1
|
232
|
-
@response = request(url(:
|
239
|
+
@response = request(url(:merb_admin_list, :model_name => "player"))
|
233
240
|
end
|
234
241
|
|
235
242
|
it "should respond sucessfully" do
|
@@ -245,7 +252,7 @@ describe "MerbAdmin" do
|
|
245
252
|
before(:each) do
|
246
253
|
MerbAdmin[:paginate] = true
|
247
254
|
MerbAdmin[:per_page] = 1
|
248
|
-
@response = request(url(:
|
255
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:page => 8})
|
249
256
|
end
|
250
257
|
|
251
258
|
it "should respond sucessfully" do
|
@@ -261,7 +268,7 @@ describe "MerbAdmin" do
|
|
261
268
|
before(:each) do
|
262
269
|
MerbAdmin[:paginate] = true
|
263
270
|
MerbAdmin[:per_page] = 1
|
264
|
-
@response = request(url(:
|
271
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:page => 17})
|
265
272
|
end
|
266
273
|
|
267
274
|
it "should respond sucessfully" do
|
@@ -277,7 +284,7 @@ describe "MerbAdmin" do
|
|
277
284
|
before(:each) do
|
278
285
|
MerbAdmin[:paginate] = true
|
279
286
|
MerbAdmin[:per_page] = 1
|
280
|
-
@response = request(url(:
|
287
|
+
@response = request(url(:merb_admin_list, :model_name => "player"), :params => {:all => true})
|
281
288
|
end
|
282
289
|
|
283
290
|
it "should respond sucessfully" do
|
@@ -287,7 +294,7 @@ describe "MerbAdmin" do
|
|
287
294
|
|
288
295
|
describe "new" do
|
289
296
|
before(:each) do
|
290
|
-
@response = request(url(:
|
297
|
+
@response = request(url(:merb_admin_new, :model_name => "player"))
|
291
298
|
end
|
292
299
|
|
293
300
|
it "should respond sucessfully" do
|
@@ -297,11 +304,24 @@ describe "MerbAdmin" do
|
|
297
304
|
it "should show \"New model\"" do
|
298
305
|
@response.body.should contain("New player")
|
299
306
|
end
|
307
|
+
|
308
|
+
it "should show required fields as \"Required\"" do
|
309
|
+
@response.body.should contain(/Name\n\s*Required/)
|
310
|
+
@response.body.should contain(/Number\n\s*Required/)
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should show non-required fields as \"Optional\"" do
|
314
|
+
@response.body.should contain(/Position\n\s*Optional/)
|
315
|
+
@response.body.should contain(/Born on\n\s*Optional/)
|
316
|
+
@response.body.should contain(/Notes\n\s*Optional/)
|
317
|
+
@response.body.should contain(/Draft\n\s*Optional/)
|
318
|
+
@response.body.should contain(/Team\n\s*Optional/)
|
319
|
+
end
|
300
320
|
end
|
301
321
|
|
302
322
|
describe "new with has-one association", :given => "a draft exists" do
|
303
323
|
before(:each) do
|
304
|
-
@response = request(url(:
|
324
|
+
@response = request(url(:merb_admin_new, :model_name => "player"))
|
305
325
|
end
|
306
326
|
|
307
327
|
it "should respond sucessfully" do
|
@@ -311,7 +331,7 @@ describe "MerbAdmin" do
|
|
311
331
|
|
312
332
|
describe "new with has-many association", :given => "three teams exist" do
|
313
333
|
before(:each) do
|
314
|
-
@response = request(url(:
|
334
|
+
@response = request(url(:merb_admin_new, :model_name => "player"))
|
315
335
|
end
|
316
336
|
|
317
337
|
it "should respond sucessfully" do
|
@@ -321,7 +341,7 @@ describe "MerbAdmin" do
|
|
321
341
|
|
322
342
|
describe "edit", :given => "a player exists" do
|
323
343
|
before(:each) do
|
324
|
-
@response = request(url(:
|
344
|
+
@response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
325
345
|
end
|
326
346
|
|
327
347
|
it "should respond sucessfully" do
|
@@ -335,22 +355,20 @@ describe "MerbAdmin" do
|
|
335
355
|
it "should show required fields as \"Required\"" do
|
336
356
|
@response.body.should contain(/Name\n\s*Required/)
|
337
357
|
@response.body.should contain(/Number\n\s*Required/)
|
338
|
-
@response.body.should contain(/Team\n\s*Required/)
|
339
358
|
end
|
340
359
|
|
341
360
|
it "should show non-required fields as \"Optional\"" do
|
342
361
|
@response.body.should contain(/Position\n\s*Optional/)
|
343
|
-
@response.body.should contain(/Batting average\n\s*Optional/)
|
344
362
|
@response.body.should contain(/Born on\n\s*Optional/)
|
345
|
-
@response.body.should contain(/Wake at\n\s*Optional/)
|
346
363
|
@response.body.should contain(/Notes\n\s*Optional/)
|
347
364
|
@response.body.should contain(/Draft\n\s*Optional/)
|
365
|
+
@response.body.should contain(/Team\n\s*Optional/)
|
348
366
|
end
|
349
367
|
end
|
350
368
|
|
351
369
|
describe "edit with has-one association", :given => "a player exists and a draft exists" do
|
352
370
|
before(:each) do
|
353
|
-
@response = request(url(:
|
371
|
+
@response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
354
372
|
end
|
355
373
|
|
356
374
|
it "should respond sucessfully" do
|
@@ -360,7 +378,7 @@ describe "MerbAdmin" do
|
|
360
378
|
|
361
379
|
describe "edit with has-many association", :given => "a player exists and three teams exist" do
|
362
380
|
before(:each) do
|
363
|
-
@response = request(url(:
|
381
|
+
@response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
364
382
|
end
|
365
383
|
|
366
384
|
it "should respond sucessfully" do
|
@@ -371,7 +389,7 @@ describe "MerbAdmin" do
|
|
371
389
|
|
372
390
|
describe "edit with missing object" do
|
373
391
|
before(:each) do
|
374
|
-
@response = request(url(:
|
392
|
+
@response = request(url(:merb_admin_edit, :model_name => "player", :id => 1))
|
375
393
|
end
|
376
394
|
|
377
395
|
it "should raise NotFound" do
|
@@ -381,11 +399,11 @@ describe "MerbAdmin" do
|
|
381
399
|
|
382
400
|
describe "create" do
|
383
401
|
before(:each) do
|
384
|
-
@response = request(url(:
|
402
|
+
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}})
|
385
403
|
end
|
386
404
|
|
387
405
|
it "should redirect to list" do
|
388
|
-
@response.should redirect_to(url(:
|
406
|
+
@response.should redirect_to(url(:merb_admin_list, :model_name => "player"))
|
389
407
|
end
|
390
408
|
|
391
409
|
it "should create a new object" do
|
@@ -395,11 +413,11 @@ describe "MerbAdmin" do
|
|
395
413
|
|
396
414
|
describe "create and edit" do
|
397
415
|
before(:each) do
|
398
|
-
@response = request(url(:
|
416
|
+
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}, :_continue => true})
|
399
417
|
end
|
400
418
|
|
401
419
|
it "should redirect to edit" do
|
402
|
-
@response.should redirect_to(url(:
|
420
|
+
@response.should redirect_to(url(:merb_admin_edit, :model_name => "player", :id => MerbAdmin::AbstractModel.new("Player").first.id))
|
403
421
|
end
|
404
422
|
|
405
423
|
it "should create a new object" do
|
@@ -409,11 +427,11 @@ describe "MerbAdmin" do
|
|
409
427
|
|
410
428
|
describe "create and add another" do
|
411
429
|
before(:each) do
|
412
|
-
@response = request(url(:
|
430
|
+
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}, :_add_another => true})
|
413
431
|
end
|
414
432
|
|
415
433
|
it "should redirect to new" do
|
416
|
-
@response.should redirect_to(url(:
|
434
|
+
@response.should redirect_to(url(:merb_admin_new, :model_name => "player"))
|
417
435
|
end
|
418
436
|
|
419
437
|
it "should create a new object" do
|
@@ -423,7 +441,7 @@ describe "MerbAdmin" do
|
|
423
441
|
|
424
442
|
describe "create with has-one association", :given => "a draft exists" do
|
425
443
|
before(:each) do
|
426
|
-
@response = request(url(:
|
444
|
+
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}, :associations => {:draft => @draft.id}})
|
427
445
|
end
|
428
446
|
|
429
447
|
it "should create a new object" do
|
@@ -437,7 +455,7 @@ describe "MerbAdmin" do
|
|
437
455
|
|
438
456
|
describe "create with has-many association", :given => "three teams exist" do
|
439
457
|
before(:each) do
|
440
|
-
@response = request(url(:
|
458
|
+
@response = request(url(:merb_admin_create, :model_name => "league"), :method => "post", :params => {:league => {:name => "National League"}, :associations => {:teams => [@teams[0].id, @teams[1].id]}})
|
441
459
|
end
|
442
460
|
|
443
461
|
it "should create a new object" do
|
@@ -454,9 +472,19 @@ describe "MerbAdmin" do
|
|
454
472
|
end
|
455
473
|
end
|
456
474
|
|
475
|
+
describe "create with uniqueness constraint violated", :given => "a player exists" do
|
476
|
+
before(:each) do
|
477
|
+
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => @player.name, :number => @player.number, :team_id => @player.team_id, :position => @player.position}})
|
478
|
+
end
|
479
|
+
|
480
|
+
it "should show an error message" do
|
481
|
+
@response.body.should contain("There is already a player with that number on this team")
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
457
485
|
describe "create with invalid object" do
|
458
486
|
before(:each) do
|
459
|
-
@response = request(url(:
|
487
|
+
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {}})
|
460
488
|
end
|
461
489
|
|
462
490
|
it "should show an error message" do
|
@@ -466,11 +494,11 @@ describe "MerbAdmin" do
|
|
466
494
|
|
467
495
|
describe "update", :given => "a player exists" do
|
468
496
|
before(:each) do
|
469
|
-
@response = request(url(:
|
497
|
+
@response = request(url(:merb_admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1}})
|
470
498
|
end
|
471
499
|
|
472
500
|
it "should redirect to list" do
|
473
|
-
@response.should redirect_to(url(:
|
501
|
+
@response.should redirect_to(url(:merb_admin_list, :model_name => "player"))
|
474
502
|
end
|
475
503
|
|
476
504
|
it "should update an object that already exists" do
|
@@ -480,11 +508,11 @@ describe "MerbAdmin" do
|
|
480
508
|
|
481
509
|
describe "update and edit", :given => "a player exists" do
|
482
510
|
before(:each) do
|
483
|
-
@response = request(url(:
|
511
|
+
@response = request(url(:merb_admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1}, :_continue => true})
|
484
512
|
end
|
485
513
|
|
486
514
|
it "should redirect to edit" do
|
487
|
-
@response.should redirect_to(url(:
|
515
|
+
@response.should redirect_to(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
488
516
|
end
|
489
517
|
|
490
518
|
it "should update an object that already exists" do
|
@@ -494,11 +522,11 @@ describe "MerbAdmin" do
|
|
494
522
|
|
495
523
|
describe "update and add another", :given => "a player exists" do
|
496
524
|
before(:each) do
|
497
|
-
@response = request(url(:
|
525
|
+
@response = request(url(:merb_admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1}, :_add_another => true})
|
498
526
|
end
|
499
527
|
|
500
528
|
it "should redirect to new" do
|
501
|
-
@response.should redirect_to(url(:
|
529
|
+
@response.should redirect_to(url(:merb_admin_new, :model_name => "player"))
|
502
530
|
end
|
503
531
|
|
504
532
|
it "should update an object that already exists" do
|
@@ -508,7 +536,7 @@ describe "MerbAdmin" do
|
|
508
536
|
|
509
537
|
describe "update with has-one association", :given => "a player exists and a draft exists" do
|
510
538
|
before(:each) do
|
511
|
-
@response = request(url(:
|
539
|
+
@response = request(url(:merb_admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}, :associations => {:draft => @draft.id}})
|
512
540
|
end
|
513
541
|
|
514
542
|
it "should update an object that already exists" do
|
@@ -522,7 +550,7 @@ describe "MerbAdmin" do
|
|
522
550
|
|
523
551
|
describe "update with has-many association", :given => "a league exists and three teams exist" do
|
524
552
|
before(:each) do
|
525
|
-
@response = request(url(:
|
553
|
+
@response = request(url(:merb_admin_update, :model_name => "league", :id => @league.id), :method => "put", :params => {:league => {:name => "National League"}, :associations => {:teams => [@teams[0].id, @teams[1].id]}})
|
526
554
|
end
|
527
555
|
|
528
556
|
it "should update an object that already exists" do
|
@@ -541,7 +569,7 @@ describe "MerbAdmin" do
|
|
541
569
|
|
542
570
|
describe "update with missing object" do
|
543
571
|
before(:each) do
|
544
|
-
@response = request(url(:
|
572
|
+
@response = request(url(:merb_admin_update, :model_name => "player", :id => 1), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1}})
|
545
573
|
end
|
546
574
|
|
547
575
|
it "should raise NotFound" do
|
@@ -551,7 +579,7 @@ describe "MerbAdmin" do
|
|
551
579
|
|
552
580
|
describe "update with invalid object", :given => "a player exists" do
|
553
581
|
before(:each) do
|
554
|
-
@response = request(url(:
|
582
|
+
@response = request(url(:merb_admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:number => "a"}})
|
555
583
|
end
|
556
584
|
|
557
585
|
it "should show an error message" do
|
@@ -561,7 +589,7 @@ describe "MerbAdmin" do
|
|
561
589
|
|
562
590
|
describe "delete", :given => "a player exists" do
|
563
591
|
before(:each) do
|
564
|
-
@response = request(url(:
|
592
|
+
@response = request(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
|
565
593
|
end
|
566
594
|
|
567
595
|
it "should respond sucessfully" do
|
@@ -575,7 +603,7 @@ describe "MerbAdmin" do
|
|
575
603
|
|
576
604
|
describe "delete with missing object" do
|
577
605
|
before(:each) do
|
578
|
-
@response = request(url(:
|
606
|
+
@response = request(url(:merb_admin_delete, :model_name => "player", :id => 1))
|
579
607
|
end
|
580
608
|
|
581
609
|
it "should raise NotFound" do
|
@@ -585,11 +613,11 @@ describe "MerbAdmin" do
|
|
585
613
|
|
586
614
|
describe "destroy", :given => "a player exists" do
|
587
615
|
before(:each) do
|
588
|
-
@response = request(url(:
|
616
|
+
@response = request(url(:merb_admin_destroy, :model_name => "player", :id => @player.id), :method => "delete")
|
589
617
|
end
|
590
618
|
|
591
619
|
it "should redirect to list" do
|
592
|
-
@response.should redirect_to(url(:
|
620
|
+
@response.should redirect_to(url(:merb_admin_list, :model_name => "player"))
|
593
621
|
end
|
594
622
|
|
595
623
|
it "should destroy an object" do
|
@@ -599,12 +627,11 @@ describe "MerbAdmin" do
|
|
599
627
|
|
600
628
|
describe "destroy with missing object" do
|
601
629
|
before(:each) do
|
602
|
-
@response = request(url(:
|
630
|
+
@response = request(url(:merb_admin_destroy, :model_name => "player", :id => 1), :method => "delete")
|
603
631
|
end
|
604
632
|
|
605
633
|
it "should raise NotFound" do
|
606
634
|
@response.status.should == 404
|
607
635
|
end
|
608
636
|
end
|
609
|
-
|
610
637
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -106,7 +106,7 @@ Merb::Test.add_helpers do
|
|
106
106
|
def mount_slice
|
107
107
|
if standalone?
|
108
108
|
Merb::Router.reset!
|
109
|
-
Merb::Router.prepare{add_slice(:merb_admin, :
|
109
|
+
Merb::Router.prepare{add_slice(:merb_admin, :path_prefix => "admin")}
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
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-
|
12
|
+
date: 2009-10-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|