merb-admin 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -2
- data/Rakefile +1 -1
- data/app/helpers/main_helper.rb +4 -4
- data/app/views/main/_belongs_to.html.erb +1 -1
- data/app/views/main/_has_many.html.erb +1 -1
- data/app/views/main/_has_one.html.erb +1 -1
- data/app/views/main/delete.html.erb +4 -4
- data/lib/abstract_model.rb +9 -7
- data/lib/merb-admin.rb +2 -1
- data/spec/migrations/activerecord/005_create_teams_migration.rb +1 -1
- data/spec/migrations/sequel/005_create_teams_migration.rb +1 -1
- data/spec/models/activerecord/team.rb +0 -1
- data/spec/models/datamapper/team.rb +1 -1
- data/spec/models/sequel/team.rb +0 -1
- data/spec/requests/main_spec.rb +70 -12
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -11,7 +11,7 @@ http://github.com/sferik/merb-admin/raw/master/screenshots/edit.png
|
|
11
11
|
== Installation
|
12
12
|
$ gem install merb-admin -s http://gemcutter.org
|
13
13
|
In your app, add the following dependency to <tt>config/dependencies.rb</tt>:
|
14
|
-
dependency "merb-admin", "0.6.
|
14
|
+
dependency "merb-admin", "0.6.5"
|
15
15
|
Add the following route to <tt>config/router.rb</tt>:
|
16
16
|
add_slice(:merb_admin, :path_prefix => "admin")
|
17
17
|
Then, run the following rake task:
|
@@ -21,6 +21,7 @@ If you're feeling crafty, you can set a couple configuration options in <tt>conf
|
|
21
21
|
Merb::BootLoader.before_app_loads do
|
22
22
|
Merb::Slices::config[:merb_admin][:app_name] = "My App"
|
23
23
|
Merb::Slices::config[:merb_admin][:per_page] = 100
|
24
|
+
Merb::Slices::config[:merb_admin][:excluded_models] = [:Top, :Secret]
|
24
25
|
end
|
25
26
|
== Usage
|
26
27
|
Start the server:
|
@@ -50,5 +51,6 @@ Many thanks to:
|
|
50
51
|
* {Aaron Wheeler}[http://fightinjoe.com/] for contributing libraries from {Merb AutoScaffold}[http://github.com/fightinjoe/merb-autoscaffold]
|
51
52
|
* {Lori Holden}[http://loriholden.com/] for contributing the merb-pagination[http://github.com/lholden/merb-pagination] helper
|
52
53
|
* {Jacques Crocker}[http://merbjedi.com] for adding support for {namespaced models}[http://github.com/merbjedi/merb-admin/commit/8139e2241038baf9b72452056fcdc7c340d79275]
|
53
|
-
* {Jeremy Evans}[http://code.jeremyevans.net] and {Pavel Kunc}[http://www.merboutpost.com] reviewing the {patch}[http://github.com/sferik/merb-admin/commit/061fa28f652fc9214e9cf480d66870140181edef] to add Sequel[http://sequel.rubyforge.org/] support
|
54
|
+
* {Jeremy Evans}[http://code.jeremyevans.net] and {Pavel Kunc}[http://www.merboutpost.com] for reviewing the {patch}[http://github.com/sferik/merb-admin/commit/061fa28f652fc9214e9cf480d66870140181edef] to add Sequel[http://sequel.rubyforge.org/] support
|
55
|
+
* {Jonah Honeyman}[http://twitter.com/jonuts] for fixing a bug[http://github.com/sferik/merb-admin/commit/9064d10382eadd1ed7a882ef40e2c6a65edfef2c] and adding the {:excluded_models option}[http://github.com/sferik/merb-admin/commit/f6157d1c471dd85162481d6926578164be1b9673]
|
54
56
|
Also, thanks to beer[http://www.21st-amendment.com].
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
9
9
|
EMAIL = "sferik@gmail.com"
|
10
10
|
HOMEPAGE = "http://github.com/sferik/merb-admin"
|
11
11
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
12
|
-
GEM_VERSION = "0.6.
|
12
|
+
GEM_VERSION = "0.6.5"
|
13
13
|
MERB_GEM_VERSION = "1.0.15"
|
14
14
|
|
15
15
|
spec = Gem::Specification.new do |s|
|
data/app/helpers/main_helper.rb
CHANGED
@@ -2,12 +2,12 @@ require 'builder'
|
|
2
2
|
module Merb
|
3
3
|
module MerbAdmin
|
4
4
|
module MainHelper
|
5
|
-
def
|
5
|
+
def object_label(object)
|
6
6
|
if object.nil?
|
7
7
|
nil
|
8
|
-
elsif object.respond_to?(:name)
|
8
|
+
elsif object.respond_to?(:name) && object.name
|
9
9
|
object.name
|
10
|
-
elsif object.respond_to?(:title)
|
10
|
+
elsif object.respond_to?(:title) && object.title
|
11
11
|
object.title
|
12
12
|
else
|
13
13
|
"#{object.class.to_s} ##{object.id}"
|
@@ -44,7 +44,7 @@ module Merb
|
|
44
44
|
when :integer
|
45
45
|
association = @abstract_model.belongs_to_associations.select{|a| a[:child_key].first == property_name}.first
|
46
46
|
if association
|
47
|
-
|
47
|
+
object_label(object.send(association[:name]))
|
48
48
|
else
|
49
49
|
object.send(property_name)
|
50
50
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%
|
2
2
|
child_key = association[:child_key].first
|
3
|
-
collection = MerbAdmin::AbstractModel.new(association[:parent_model]).all.map{|
|
3
|
+
collection = MerbAdmin::AbstractModel.new(association[:parent_model]).all.map{|object| [object.id, object_label(object)]}.sort_by{|object| object[1]}
|
4
4
|
selected = @object.send(child_key)
|
5
5
|
label = association[:pretty_name]
|
6
6
|
required = false
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%
|
2
2
|
association_name = association[:name]
|
3
|
-
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|
|
3
|
+
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|object| [object.id, object_label(object)]}.sort_by{|object| object[1]}
|
4
4
|
selected = @object.send(association_name)
|
5
5
|
label = association[:pretty_name]
|
6
6
|
%>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%
|
2
2
|
child_key = association[:child_key].first
|
3
3
|
association_name = association[:name]
|
4
|
-
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|
|
4
|
+
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|object| [object.id, object_label(object)]}.sort_by{|object| object[1]}
|
5
5
|
selected = @object.send(association_name)
|
6
6
|
label = association[:pretty_name]
|
7
7
|
required = false
|
@@ -1,12 +1,12 @@
|
|
1
|
-
<p>Are you sure you want to delete the <%= @abstract_model.pretty_name.downcase %> “<%=
|
1
|
+
<p>Are you sure you want to delete the <%= @abstract_model.pretty_name.downcase %> “<%= object_label(@object) %>”? All of the following related items will be deleted:</p>
|
2
2
|
<ul>
|
3
3
|
<li>
|
4
|
-
<%= @abstract_model.pretty_name %>: <%= link_to(
|
4
|
+
<%= @abstract_model.pretty_name %>: <%= link_to(object_label(@object), url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => @object.id)) %>
|
5
5
|
<ul>
|
6
6
|
<% @abstract_model.has_many_associations.each do |association| %>
|
7
7
|
<% @object.send(association[:name]).reject{|child| child.nil?}.each do |child| %>
|
8
8
|
<li>
|
9
|
-
One or more <%= @abstract_model.pretty_name.pluralize.downcase %> in <%= association[:pretty_name].downcase %>: <%= link_to(
|
9
|
+
One or more <%= @abstract_model.pretty_name.pluralize.downcase %> in <%= association[:pretty_name].downcase %>: <%= link_to(object_label(child), url(:merb_admin_edit, :model_name => association[:name].to_s.singularize.to_sym, :id => child.id)) %>
|
10
10
|
</li>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<% child = @object.send(association[:name]) %>
|
15
15
|
<% next if child.nil? %>
|
16
16
|
<li>
|
17
|
-
A <%= @abstract_model.pretty_name.downcase %> in <%= association[:pretty_name].downcase %>: <%= link_to(
|
17
|
+
A <%= @abstract_model.pretty_name.downcase %> in <%= association[:pretty_name].downcase %>: <%= link_to(object_label(child), url(:merb_admin_edit, :model_name => association[:name], :id => child.id)) %>
|
18
18
|
</li>
|
19
19
|
<% end %>
|
20
20
|
</ul>
|
data/lib/abstract_model.rb
CHANGED
@@ -4,29 +4,31 @@ module MerbAdmin
|
|
4
4
|
class AbstractModel
|
5
5
|
# Returns all models for a given Merb app
|
6
6
|
def self.all
|
7
|
-
return @models if @models
|
8
7
|
@models = []
|
9
8
|
orm = Merb.orm
|
10
9
|
case orm
|
11
10
|
when :activerecord, :sequel
|
12
11
|
Dir.glob(Merb.dir_for(:model) / Merb.glob_for(:model)).each do |filename|
|
13
12
|
File.read(filename).scan(/class ([\w\d_\-:]+)/).flatten.each do |model_name|
|
14
|
-
|
15
|
-
@models << new(model) if model
|
13
|
+
add_model(model_name.to_sym)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
when :datamapper
|
19
17
|
DataMapper::Model.descendants.each do |model_name|
|
20
|
-
|
21
|
-
next if m == Merb::DataMapperSessionStore if Merb.const_defined?(:DataMapperSessionStore)
|
22
|
-
model = lookup(model_name.to_s.to_sym)
|
23
|
-
@models << new(model) if model
|
18
|
+
add_model(model_name.to_s.to_sym)
|
24
19
|
end
|
25
20
|
else
|
26
21
|
raise "MerbAdmin does not support the #{orm} ORM"
|
27
22
|
end
|
28
23
|
@models.sort!{|x, y| x.model.to_s <=> y.model.to_s}
|
29
24
|
end
|
25
|
+
|
26
|
+
def self.add_model(name)
|
27
|
+
puts MerbAdmin[:excluded_models].inspect
|
28
|
+
return if MerbAdmin[:excluded_models].include?(name)
|
29
|
+
model = lookup(name)
|
30
|
+
@models << new(model) if model
|
31
|
+
end
|
30
32
|
|
31
33
|
# Given a symbol +model_name+, finds the corresponding model class
|
32
34
|
def self.lookup(model_name)
|
data/lib/merb-admin.rb
CHANGED
@@ -17,13 +17,14 @@ if defined?(Merb::Plugins)
|
|
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
19
|
Merb::Slices::config[:merb_admin][:per_page] ||= 100
|
20
|
+
Merb::Slices::config[:merb_admin][:excluded_models] ||= []
|
20
21
|
|
21
22
|
# All Slice code is expected to be namespaced inside a module
|
22
23
|
module MerbAdmin
|
23
24
|
|
24
25
|
# Slice metadata
|
25
26
|
self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
26
|
-
self.version = "0.6.
|
27
|
+
self.version = "0.6.5"
|
27
28
|
self.author = "Erik Michaels-Ober"
|
28
29
|
|
29
30
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
@@ -4,7 +4,7 @@ class CreateTeamsMigration < ActiveRecord::Migration
|
|
4
4
|
t.timestamps
|
5
5
|
t.integer(:league_id)
|
6
6
|
t.integer(:division_id)
|
7
|
-
t.string(:name, :limit => 50
|
7
|
+
t.string(:name, :limit => 50)
|
8
8
|
t.string(:logo_url, :limit => 255)
|
9
9
|
t.string(:manager, :limit => 100, :null => false)
|
10
10
|
t.string(:ballpark, :limit => 100)
|
@@ -6,7 +6,7 @@ class CreateTeams < Sequel::Migration
|
|
6
6
|
DateTime(:updated_at)
|
7
7
|
foreign_key(:league_id, :table => :leagues)
|
8
8
|
foreign_key(:division_id, :table => :divisions)
|
9
|
-
String(:name, :limit => 50
|
9
|
+
String(:name, :limit => 50)
|
10
10
|
String(:logo_url, :limit => 255)
|
11
11
|
String(:manager, :limit => 100, :null => false)
|
12
12
|
String(:ballpark, :limit => 100)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class Team < ActiveRecord::Base
|
2
2
|
validates_numericality_of(:league_id, :only_integer => true)
|
3
3
|
validates_numericality_of(:division_id, :only_integer => true)
|
4
|
-
validates_presence_of(:name)
|
5
4
|
validates_presence_of(:manager)
|
6
5
|
validates_numericality_of(:founded, :only_integer => true)
|
7
6
|
validates_numericality_of(:wins, :only_integer => true)
|
@@ -6,7 +6,7 @@ class Team
|
|
6
6
|
property(:updated_at, DateTime)
|
7
7
|
property(:league_id, Integer, :nullable => false, :index => true)
|
8
8
|
property(:division_id, Integer, :nullable => false, :index => true)
|
9
|
-
property(:name, String, :
|
9
|
+
property(:name, String, :index => true)
|
10
10
|
property(:logo_url, String, :length => 255)
|
11
11
|
property(:manager, String, :length => 100, :nullable => false, :index => true)
|
12
12
|
property(:ballpark, String, :length => 100, :index => true)
|
data/spec/models/sequel/team.rb
CHANGED
@@ -12,7 +12,6 @@ class Team < Sequel::Model
|
|
12
12
|
def validate
|
13
13
|
validates_numeric(:league_id, :only_integer => true)
|
14
14
|
validates_numeric(:division_id, :only_integer => true)
|
15
|
-
validates_presence(:name)
|
16
15
|
validates_presence(:manager)
|
17
16
|
validates_numeric(:founded, :only_integer => true)
|
18
17
|
validates_numeric(:wins, :only_integer => true)
|
data/spec/requests/main_spec.rb
CHANGED
@@ -10,15 +10,15 @@ end
|
|
10
10
|
|
11
11
|
given "two players exist" do
|
12
12
|
@players = []
|
13
|
-
2.
|
14
|
-
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
13
|
+
(1..2).each do |number|
|
14
|
+
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => number, :name => "Player #{number}")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
given "three teams exist" do
|
19
19
|
@teams = []
|
20
|
-
3.
|
21
|
-
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{
|
20
|
+
(1..3).each do |number|
|
21
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -30,23 +30,31 @@ end
|
|
30
30
|
given "a player exists and three teams exist" do
|
31
31
|
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
|
32
32
|
@teams = []
|
33
|
-
3.
|
34
|
-
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{
|
33
|
+
(1..3).each do |number|
|
34
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
given "a player exists and three teams with no name exist" do
|
39
|
+
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
|
40
|
+
@teams = []
|
41
|
+
(1..3).each do |number|
|
42
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
38
46
|
given "a league exists and three teams exist" do
|
39
|
-
@league = League.create(:name => "League 1")
|
47
|
+
@league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
|
40
48
|
@teams = []
|
41
|
-
3.
|
42
|
-
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{
|
49
|
+
(1..3).each do |number|
|
50
|
+
@teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
46
54
|
given "twenty players exist" do
|
47
55
|
@players = []
|
48
|
-
20.
|
49
|
-
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number =>
|
56
|
+
(1..20).each do |number|
|
57
|
+
@players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => number, :name => "Player #{number}")
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
@@ -72,6 +80,25 @@ describe "MerbAdmin" do
|
|
72
80
|
it "should show \"Site administration\"" do
|
73
81
|
@response.body.should contain("Site administration")
|
74
82
|
end
|
83
|
+
|
84
|
+
it "should be sorted correctly" do
|
85
|
+
@response.body.should contain(/Division.*Draft.*League.*Player.*Team/m)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "dashboard with excluded models" do
|
90
|
+
before(:each) do
|
91
|
+
MerbAdmin[:excluded_models] = [:Player]
|
92
|
+
@response = request(url(:merb_admin_dashboard))
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should respond sucessfully" do
|
96
|
+
@response.should be_successful
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should not contain excluded models" do
|
100
|
+
@response.body.should_not contain(/Player/)
|
101
|
+
end
|
75
102
|
end
|
76
103
|
|
77
104
|
describe "list" do
|
@@ -347,6 +374,16 @@ describe "MerbAdmin" do
|
|
347
374
|
end
|
348
375
|
end
|
349
376
|
|
377
|
+
describe "new with missing label", :given => "a player exists and three teams with no name exist" do
|
378
|
+
before(:each) do
|
379
|
+
@response = request(url(:merb_admin_new, :model_name => "player"))
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should respond sucessfully" do
|
383
|
+
@response.should be_successful
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
350
387
|
describe "edit", :given => "a player exists" do
|
351
388
|
before(:each) do
|
352
389
|
@response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
@@ -402,7 +439,6 @@ describe "MerbAdmin" do
|
|
402
439
|
end
|
403
440
|
end
|
404
441
|
|
405
|
-
|
406
442
|
describe "edit with missing object" do
|
407
443
|
before(:each) do
|
408
444
|
@response = request(url(:merb_admin_edit, :model_name => "player", :id => 1))
|
@@ -413,6 +449,16 @@ describe "MerbAdmin" do
|
|
413
449
|
end
|
414
450
|
end
|
415
451
|
|
452
|
+
describe "edit with missing label", :given => "a player exists and three teams with no name exist" do
|
453
|
+
before(:each) do
|
454
|
+
@response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
455
|
+
end
|
456
|
+
|
457
|
+
it "should respond sucessfully" do
|
458
|
+
@response.should be_successful
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
416
462
|
describe "create" do
|
417
463
|
before(:each) do
|
418
464
|
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}})
|
@@ -633,6 +679,18 @@ describe "MerbAdmin" do
|
|
633
679
|
end
|
634
680
|
end
|
635
681
|
|
682
|
+
describe "delete with missing label" do
|
683
|
+
before(:each) do
|
684
|
+
@league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
|
685
|
+
@team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => rand(99999), :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
|
686
|
+
@response = request(url(:merb_admin_delete, :model_name => "league", :id => @league.id))
|
687
|
+
end
|
688
|
+
|
689
|
+
it "should respond sucessfully" do
|
690
|
+
@response.should be_successful
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
636
694
|
describe "destroy", :given => "a player exists" do
|
637
695
|
before(:each) do
|
638
696
|
@response = request(url(:merb_admin_destroy, :model_name => "player", :id => @player.id), :method => "delete")
|
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.6.
|
4
|
+
version: 0.6.5
|
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-11-
|
12
|
+
date: 2009-11-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|