sferik-merb-admin 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # MerbAdmin
2
2
 
3
- **MerbAdmin is a merb slice that provides an easy-to-use interface for managing your data.**
3
+ **MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.**
4
4
 
5
5
  It currently offers the features listed [here](http://sferik.tadalist.com/lists/1352791/public).
6
6
 
@@ -14,7 +14,7 @@ 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.5", :require_as => "merb-admin"
17
+ dependency "sferik-merb-admin", "0.2.6", :require_as => "merb-admin"
18
18
 
19
19
  Add the following route to `config/router.rb`:
20
20
 
data/Rakefile CHANGED
@@ -11,8 +11,8 @@ GEM_NAME = "merb-admin"
11
11
  AUTHOR = "Erik Michaels-Ober"
12
12
  EMAIL = "sferik@gmail.com"
13
13
  HOMEPAGE = "http://twitter.com/sferik"
14
- SUMMARY = "MerbAdmin is a merb slice that provides an easy-to-use interface for managing your data."
15
- GEM_VERSION = "0.2.5"
14
+ SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
15
+ GEM_VERSION = "0.2.6"
16
16
 
17
17
  spec = Gem::Specification.new do |s|
18
18
  s.rubyforge_project = "merb"
@@ -1,6 +1,6 @@
1
1
  <% value = eval("@instance.#{property.field}") %>
2
2
  <div>
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) %>
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">
5
5
  <%= !property.nullable? ? "Required." : "Optional." %>
6
6
  </p>
data/lib/merb-admin.rb CHANGED
@@ -7,7 +7,7 @@ if defined?(Merb::Plugins)
7
7
 
8
8
  # Register the Slice for the current host application
9
9
  Merb::Slices::register(__FILE__)
10
-
10
+
11
11
  # Slice configuration - set this in a before_app_loads callback.
12
12
  # By default a Slice uses its own layout, so you can swicht to
13
13
  # the main application layout or no layout at all if needed.
@@ -19,32 +19,30 @@ if defined?(Merb::Plugins)
19
19
 
20
20
  # All Slice code is expected to be namespaced inside a module
21
21
  module MerbAdmin
22
-
22
+
23
23
  # Slice metadata
24
24
  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.5"
25
+ self.version = "0.2.6"
26
26
  self.author = "Erik Michaels-Ober"
27
-
27
+
28
28
  # Stub classes loaded hook - runs before LoadClasses BootLoader
29
29
  # right after a slice's classes have been loaded internally.
30
30
  def self.loaded
31
- require "dm-is-paginated"
32
31
  end
33
-
32
+
34
33
  # Initialization hook - runs before AfterAppLoads BootLoader
35
34
  def self.init
36
35
  end
37
-
36
+
38
37
  # Activation hook - runs after AfterAppLoads BootLoader
39
38
  def self.activate
40
39
  end
41
-
40
+
42
41
  # Deactivation hook - triggered by Merb::Slices.deactivate(MerbAdmin)
43
42
  def self.deactivate
44
43
  end
45
-
46
- def self.setup_router(scope)
47
44
 
45
+ def self.setup_router(scope)
48
46
  scope.match("/admin(/index)", :method => :get).
49
47
  to(:controller => "forms", :action => "index").
50
48
  name(:admin_dashboard)
@@ -76,11 +74,10 @@ if defined?(Merb::Plugins)
76
74
  scope.match("/admin/:model_name/:id(.:format)", :method => :delete).
77
75
  to(:controller => "forms", :action => "destroy").
78
76
  name(:admin_destroy)
79
-
80
77
  end
81
-
78
+
82
79
  end
83
-
80
+
84
81
  # Setup the slice layout for MerbAdmin
85
82
  #
86
83
  # Use MerbAdmin.push_path and MerbAdmin.push_app_path
@@ -94,8 +91,8 @@ if defined?(Merb::Plugins)
94
91
  #
95
92
  # Or just call setup_default_structure! to setup a basic Merb MVC structure.
96
93
  MerbAdmin.setup_default_structure!
97
-
94
+
98
95
  # Add dependencies for other MerbAdmin classes below. Example:
99
96
  # dependency "merb-admin/other"
100
-
97
+
101
98
  end
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,26 @@
1
+ class Player
2
+ include DataMapper::Resource
3
+
4
+ property :id, Serial
5
+ property :created_at, DateTime
6
+ property :updated_at, DateTime
7
+ property :deleted_at, ParanoidDateTime
8
+ property :team_id, Integer, :nullable => false, :index => true
9
+ property :name, String, :length => 100, :nullable => false, :index => true
10
+ property :position, Flag[:pitcher, :catcher, :first, :second, :third, :shortstop, :left, :center, :right]
11
+ property :sex, Enum[:male, :female]
12
+ property :batting_average, Float, :default => 0.0, :precision => 4, :scale => 3
13
+ property :injured, Boolean, :default => false
14
+ property :retired, TrueClass, :default => false
15
+ property :born_on, Date
16
+ property :wake_at, Time
17
+ property :notes, Text
18
+
19
+ # belongs_to :team
20
+ end
21
+
22
+ Player.fixture {{
23
+ :name => "#{/\w{3,10}/.gen.capitalize} #{/\w{5,10}/.gen.capitalize}",
24
+ :sex => Player.properties[:sex].type.flag_map.values[rand(Player.properties[:sex].type.flag_map.length)],
25
+ :team_id => 1,
26
+ }}
data/spec/fixtures.rb ADDED
@@ -0,0 +1,10 @@
1
+ # Learn more at http://github.com/datamapper/dm-more/tree/master/dm-sweatshop
2
+ require 'dm-sweatshop'
3
+ # Learn more at http://github.com/datamapper/dm-more/tree/master/dm-types
4
+ require 'dm-types'
5
+ require 'dm-aggregates'
6
+ require 'dm-validations'
7
+
8
+ Dir['spec/fixtures/**/*_fixture.rb'].sort.each do |fixture_file|
9
+ require fixture_file
10
+ end
@@ -0,0 +1,204 @@
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
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,9 @@ require 'merb-core'
3
3
  require 'merb-slices'
4
4
  require 'merb-helpers'
5
5
  require 'merb-assets'
6
+ require 'merb-action-args'
6
7
  require 'spec'
8
+ require 'spec/fixtures'
7
9
 
8
10
  # Add merb-admin.rb to the search path
9
11
  Merb::Plugins.config[:merb_slices][:auto_register] = true
@@ -19,9 +21,13 @@ Merb.start_environment(
19
21
  :testing => true,
20
22
  :adapter => 'runner',
21
23
  :environment => ENV['MERB_ENV'] || 'test',
24
+ :merb_root => Merb.root,
22
25
  :session_store => 'memory'
23
26
  )
24
27
 
28
+ # DataMapper.setup(:default, 'sqlite3::memory:') && DataMapper.auto_migrate!
29
+ DataMapper.setup(:default, 'sqlite3:test.db')
30
+
25
31
  module Merb
26
32
  module Test
27
33
  module SliceHelper
@@ -51,10 +57,10 @@ end
51
57
  #
52
58
  Merb::Test.add_helpers do
53
59
  def mount_slice
54
- Merb::Router.prepare { add_slice(:MerbAdmin) } if standalone?
60
+ if standalone?
61
+ Merb::Router.reset!
62
+ Merb::Router.prepare { add_slice(:MerbAdmin, :name_prefix => nil, :path_prefix => "", :default_routes => false) }
63
+ end
55
64
  end
56
65
 
57
- def dismount_slice
58
- Merb::Router.reset! if standalone?
59
- end
60
66
  end
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.5
4
+ version: 0.2.6
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-11 00:00:00 -07:00
12
+ date: 2009-08-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,7 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 0.0.1
54
54
  version:
55
- description: MerbAdmin is a merb slice that provides an easy-to-use interface for managing your data.
55
+ description: MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.
56
56
  email: sferik@gmail.com
57
57
  executables: []
58
58
 
@@ -70,9 +70,13 @@ files:
70
70
  - lib/merb-admin/slicetasks.rb
71
71
  - lib/merb-admin/spectasks.rb
72
72
  - lib/merb-admin.rb
73
- - spec/controller
74
- - spec/controller/forms_spec.rb
75
- - spec/merb-admin_spec.rb
73
+ - spec/controllers
74
+ - spec/controllers/forms_spec.rb
75
+ - spec/fixtures
76
+ - spec/fixtures/user_fixture.rb
77
+ - spec/fixtures.rb
78
+ - spec/requests
79
+ - spec/requests/forms_spec.rb
76
80
  - spec/spec_helper.rb
77
81
  - app/controllers
78
82
  - app/controllers/application.rb
@@ -208,6 +212,6 @@ rubyforge_project: merb
208
212
  rubygems_version: 1.3.5
209
213
  signing_key:
210
214
  specification_version: 3
211
- summary: MerbAdmin is a merb slice that provides an easy-to-use interface for managing your data.
215
+ summary: MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.
212
216
  test_files: []
213
217
 
@@ -1,41 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
-
3
- describe "MerbAdmin::Forms (controller)" do
4
-
5
- before(:each) do
6
- mount_slice
7
- end
8
-
9
- after(:each) do
10
- dismount_slice
11
- end
12
-
13
- it "should have access to the slice module" do
14
- controller = dispatch_to(MerbAdmin::Forms, :index)
15
- controller.slice.should == MerbAdmin
16
- controller.slice.should == MerbAdmin::Forms.slice
17
- end
18
-
19
- it "should have an index action" do
20
- controller = dispatch_to(MerbAdmin::Forms, :index)
21
- controller.status.should == 200
22
- controller.body.should contain("MerbAdmin")
23
- end
24
-
25
- it "should have helper methods for dealing with public paths" do
26
- controller = dispatch_to(MerbAdmin::Forms, :index)
27
- controller.public_path_for(:image).should == "/slices/merb-admin/images"
28
- controller.public_path_for(:javascript).should == "/slices/merb-admin/javascripts"
29
- controller.public_path_for(:stylesheet).should == "/slices/merb-admin/stylesheets"
30
-
31
- controller.image_path.should == "/slices/merb-admin/images"
32
- controller.javascript_path.should == "/slices/merb-admin/javascripts"
33
- controller.stylesheet_path.should == "/slices/merb-admin/stylesheets"
34
- end
35
-
36
- it "should have a slice-specific _template_root" do
37
- MerbAdmin::Forms._template_root.should == MerbAdmin.dir_for(:view)
38
- MerbAdmin::Forms._template_root.should == MerbAdmin::Application._template_root
39
- end
40
-
41
- end
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "MerbAdmin (module)" do
4
-
5
- end