quirkey-qadmin 0.1.1 → 0.2.0

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.
Files changed (42) hide show
  1. data/History.txt +5 -0
  2. data/LICENSE +20 -0
  3. data/Manifest.txt +20 -12
  4. data/PostInstall.txt +1 -1
  5. data/README.rdoc +4 -29
  6. data/Rakefile +5 -3
  7. data/lib/qadmin.rb +4 -2
  8. data/lib/qadmin/assets/form_builder.rb +36 -0
  9. data/lib/qadmin/configuration.rb +48 -0
  10. data/lib/qadmin/controller.rb +64 -34
  11. data/lib/qadmin/form_builder.rb +23 -0
  12. data/lib/qadmin/helper.rb +46 -15
  13. data/lib/qadmin/option_set.rb +48 -0
  14. data/lib/qadmin/overlay.rb +31 -0
  15. data/lib/qadmin/page_titles.rb +34 -0
  16. data/lib/qadmin/templates.rb +52 -0
  17. data/lib/qadmin/views/content_forms/_attachments_form.erb +0 -0
  18. data/lib/qadmin/views/content_forms/_photos_form.erb +4 -0
  19. data/lib/qadmin/views/content_forms/_videos_form.erb +0 -0
  20. data/lib/qadmin/views/default/edit.erb +12 -0
  21. data/lib/qadmin/views/default/index.erb +9 -0
  22. data/lib/qadmin/views/default/new.erb +12 -0
  23. data/lib/qadmin/views/default/show.erb +7 -0
  24. data/rails/init.rb +2 -1
  25. data/rails_generators/qadmin/qadmin_generator.rb +36 -19
  26. data/rails_generators/qadmin/templates/_form.html.erb +7 -0
  27. data/rails_generators/qadmin/templates/_instance.html.erb +8 -0
  28. data/rails_generators/qadmin/templates/controller.rb +1 -1
  29. data/rails_generators/qadmin/templates/functional_test.rb +102 -65
  30. data/rails_generators/qadmin/templates/images/{icon_up.gif → icon_asc.gif} +0 -0
  31. data/rails_generators/qadmin/templates/images/{icon_down.gif → icon_desc.gif} +0 -0
  32. data/rails_generators/qadmin/templates/layout.html.erb +45 -0
  33. data/test/test_helper.rb +8 -0
  34. data/test/test_qadmin_controller.rb +16 -6
  35. data/test/test_qadmin_generator.rb +17 -2
  36. data/test/test_qadmin_option_set.rb +86 -0
  37. metadata +46 -14
  38. data/rails_generators/qadmin/templates/shoulda_functional_test.rb +0 -33
  39. data/script/console +0 -10
  40. data/script/destroy +0 -14
  41. data/script/generate +0 -14
  42. data/script/txt2html +0 -71
@@ -0,0 +1,8 @@
1
+ <div id="<%%= dom_id(@<%= file_name %>) %>">
2
+ <div class="fields_group">
3
+ <% attributes.each do |attribute| -%>
4
+ <h5><%= attribute.human_name %>:</h5>
5
+ <%%= h @<%= singular_name %>.<%= attribute.name %> %>
6
+ <% end -%>
7
+ </div>
8
+ </div>
@@ -1,6 +1,6 @@
1
1
  class <%= controller_class_name %>Controller < ApplicationController
2
2
  #before_filter :login_required
3
- #layout 'admin'
3
+ layout 'admin'
4
4
  qadmin
5
5
 
6
6
  end
@@ -1,77 +1,114 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper'
2
- require '<%= controller_file_path %>_controller'
1
+ require 'test_helper'
3
2
 
4
- # Re-raise errors caught by the controller.
5
- class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ context "<%= controller_class_name %>" do
6
+ setup do
7
+ @<%= file_name %> = <%= table_name %>(!!FIXTURE_NAME)
8
+ @<%= file_name %>_params = {
9
+ <%= attributes.collect { |a| ":#{a.name} => '#{a.default}'" }.join(",\n\t") %>
10
+ }
11
+ end
6
12
 
7
- class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
- fixtures :<%= model_name.tableize %>#, :users
13
+ context "html" do
14
+ context "GET index" do
15
+ setup do
16
+ get :index
17
+ end
9
18
 
10
- def setup
11
- @controller = <%= controller_class_name %>Controller.new
12
- @request = ActionController::TestRequest.new
13
- @response = ActionController::TestResponse.new
14
- #login_as(:aaron)
15
- @<%= file_name %> = <%= model_name.tableize %>(!!FIXTURENAME)
16
- end
19
+ should_respond_with :success
17
20
 
18
- # def test_should_require_login
19
- # logout
20
- # get :index
21
- # assert_redirected_to_login
22
- # end
21
+ should "load paginated collection of <%= table_name %>" do
22
+ assert assigns(:<%= table_name %>)
23
+ assert assigns(:<%= table_name %>).respond_to?(:next_page)
24
+ end
23
25
 
24
- def test_should_get_index
25
- get :index
26
- assert_response :success
27
- assert assigns(:<%= model_name.tableize %>)
28
- end
26
+ should "display <%= file_name %>" do
27
+ assert_select "#<%= file_name %>_#{@<%= file_name %>.id}"
28
+ end
29
+ end
29
30
 
30
- def test_should_get_new
31
- get :new
32
- assert_response :success
33
- assert_select 'form'
34
- end
35
-
36
- def test_should_create_<%= file_name %>
37
- assert_difference '<%= model_name %>.count' do
38
- post :create, :<%= file_name %> => <%= file_name %>_params
39
- assert_redirected_to <%= table_name.singularize %>_path(assigns(:<%= file_name %>))
40
- end
41
- end
31
+ context "GET show" do
32
+ setup do
33
+ get :show, :id => @<%= file_name %>.id
34
+ end
42
35
 
43
- def test_should_show_<%= file_name %>
44
- get :show, :id => @<%= file_name %>.id
45
- assert_response :success
46
- assert assigns(:<%= file_name %>)
47
- end
36
+ should_respond_with :success
37
+ should_assign_to :<%= file_name %>
48
38
 
49
- def test_should_get_edit
50
- get :edit, :id => @<%= file_name %>.id
51
- assert_response :success
52
- assert assigns(:<%= file_name %>)
53
- assert_select 'form'
54
- end
55
-
56
- def test_should_update_<%= file_name %>
57
- assert_no_difference '<%= model_name %>.count' do
58
- put :update, :id => @<%= file_name %>.id, :<%= file_name %> => <%= file_name %>_params
59
- assert_redirected_to <%= table_name.singularize %>_path(assigns(:<%= file_name %>))
60
- end
61
- end
62
-
63
- def test_should_destroy_<%= file_name %>
64
- assert_difference '<%= model_name %>.count', -1 do
65
- delete :destroy, :id => @<%= file_name %>.id
66
- assert_redirected_to <%= table_name %>_path
39
+ should "load <%= file_name %>" do
40
+ assert_equal @<%= file_name %>, assigns(:<%= file_name %>)
41
+ end
42
+
43
+ should "display <%= file_name %>" do
44
+ assert_select "#<%= file_name %>_#{@<%= file_name %>.id}"
45
+ end
46
+ end
47
+
48
+ context "GET new" do
49
+ setup do
50
+ get :new
51
+ end
52
+
53
+ should_respond_with :success
54
+ should_assign_to :<%= file_name %>
55
+
56
+ should "display form" do
57
+ assert_select 'form'
58
+ end
59
+ end
60
+
61
+ context "POST create with valid <%= file_name %>" do
62
+ setup do
63
+ post :create, :<%= file_name %> => @<%= file_name %>_params
64
+ end
65
+
66
+ should_change '<%= model_name %>.count', :by => 1
67
+ should_redirect_to "<%= file_name %>_path(@<%= file_name %>)"
68
+ should_assign_to :<%= file_name %>
69
+ end
70
+
71
+ context "GET edit" do
72
+ setup do
73
+ get :edit, :id => @<%= file_name %>.id
74
+ end
75
+
76
+ should_respond_with :success
77
+ should_assign_to :<%= file_name %>
78
+
79
+ should "load <%= file_name %>" do
80
+ assert_equal @<%= file_name %>, assigns(:<%= file_name %>)
81
+ end
82
+
83
+ should "display form" do
84
+ assert_select 'form'
85
+ end
86
+ end
87
+
88
+ context "PUT update" do
89
+ setup do
90
+ put :update, :id => @<%= file_name %>.id, :<%= file_name %> => @<%= file_name %>_params
91
+ end
92
+
93
+ should_not_change '<%= model_name %>.count'
94
+ should_redirect_to "<%= file_name %>_path(@<%= file_name %>)"
95
+ should_assign_to :<%= file_name %>
96
+
97
+ should "load <%= file_name %>" do
98
+ assert_equal @<%= file_name %>, assigns(:<%= file_name %>)
99
+ end
100
+ end
101
+
102
+ context "DELETE destroy" do
103
+ setup do
104
+ delete :destroy, :id => @<%= file_name %>.id
105
+ end
106
+
107
+ should_change '<%= model_name %>.count', :by => -1
108
+ should_redirect_to "<%= table_name %>_path"
109
+ should_assign_to :<%= file_name %>
110
+ end
67
111
  end
68
112
  end
69
113
 
70
-
71
- protected
72
- def <%= file_name %>_params(options = {})
73
- {
74
- <%= attributes.collect { |a| ":#{a.name} => #{a.default}" }.join(', ') %>
75
- }.update(options)
76
- end
77
114
  end
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+
8
+ <title>Admin</title>
9
+
10
+ <%%= stylesheet_link_tag 'admin' %>
11
+ <%%= javascript_include_tag :defaults %>
12
+ <%%= javascript_include_tag 'file_browser' %>
13
+ </head>
14
+ <body>
15
+ <div id="header">
16
+ <h1>Admin</h1>
17
+ <div id="loginbox"><%% if logged_in? %>Welcome, <%%= current_user %> / <%%= link_to "Logout", '/logout' %><%% else %><%%= link_to "Login", '/login' %><%% end %></div>
18
+ </div>
19
+ <div id="main">
20
+ <div id="left_menu">
21
+ <h3>Panels</h3>
22
+ <ul class="menu">
23
+ <%% simple_menu([]) do |name,controller| %>
24
+ <li><%%= link_to(name.titleize, {:controller => controller}, :class => (like_current_page?(:controller => controller) ? 'selected' : '')) %></li>
25
+ <%% end %>
26
+ </ul>
27
+ <h3>Quick Links</h3>
28
+ <ul class="menu">
29
+ </ul>
30
+ </div>
31
+ <div id="content">
32
+ <%% if flash[:message] %>
33
+ <div id="message_main" class="message">
34
+ <%%= h flash[:message] %>
35
+ </div>
36
+ <%% elsif flash[:warning] %>
37
+ <div id="message_main" class="message warning">
38
+ <%%= h flash[:warning] %>
39
+ </div>
40
+ <%% end %>
41
+ <%%= yield %>
42
+ </div>
43
+ </div>
44
+ </body>
45
+ </html>
@@ -17,6 +17,10 @@ module ActiveRecord
17
17
  []
18
18
  end
19
19
 
20
+ def column_names
21
+ ['id'] #content_columns.collect {|c| c.name }
22
+ end
23
+
20
24
  end
21
25
  self.pluralize_table_names = true
22
26
  end
@@ -59,6 +63,10 @@ class Item < ActiveRecord::Base
59
63
  MockColumn.new(name, type)
60
64
  end
61
65
  end
66
+
67
+ def column_names
68
+ [] #content_columns.collect {|c| c.name }
69
+ end
62
70
  end
63
71
  end
64
72
 
@@ -16,7 +16,7 @@ class TestQadminController < Test::Unit::TestCase
16
16
  def assert_does_not_define_actions(*actions)
17
17
  [actions].flatten.each do |action|
18
18
  assert !@controller.respond_to?(action), "Should not define ##{action}"
19
- end
19
+ end
20
20
  end
21
21
  public
22
22
 
@@ -26,6 +26,7 @@ class TestQadminController < Test::Unit::TestCase
26
26
 
27
27
  context "with no options" do
28
28
  setup do
29
+ class ::NoOption < ActiveRecord::Base; end
29
30
  class NoOptionsController < MockController
30
31
  qadmin
31
32
  end
@@ -36,6 +37,10 @@ class TestQadminController < Test::Unit::TestCase
36
37
  assert_defines_actions(crud_actions)
37
38
  end
38
39
 
40
+ should "set qadmin configuration" do
41
+ assert @controller.send(:qadmin_configuration).is_a?(Qadmin::Configuration)
42
+ end
43
+
39
44
  should "set model_name from controller name" do
40
45
  assert_equal 'NoOption', @controller.send(:model_name)
41
46
  end
@@ -52,8 +57,9 @@ class TestQadminController < Test::Unit::TestCase
52
57
  context "with hashed options" do
53
58
  context "with :exclude" do
54
59
  setup do
60
+ class ::Exclude < ActiveRecord::Base; end
55
61
  class ExcludeController < MockController
56
- qadmin :exclude => [:show, :destroy]
62
+ qadmin :available_actions => {:exclude => [:show, :destroy]}
57
63
  end
58
64
  @controller = ExcludeController.new
59
65
  end
@@ -69,8 +75,9 @@ class TestQadminController < Test::Unit::TestCase
69
75
 
70
76
  context "with :only" do
71
77
  setup do
78
+ class ::Only < ActiveRecord::Base; end
72
79
  class OnlyController < MockController
73
- qadmin :only => [:index, :show]
80
+ qadmin :available_actions => {:only => [:index, :show]}
74
81
  end
75
82
  @controller = OnlyController.new
76
83
  end
@@ -103,12 +110,15 @@ class TestQadminController < Test::Unit::TestCase
103
110
 
104
111
  context "with two instances in different controllers" do
105
112
  setup do
113
+ class ::NewExclude < ActiveRecord::Base; end
106
114
  class NewExcludeController < MockController
107
- qadmin :exclude => [:show, :new]
115
+ qadmin do |config|
116
+ config.available_actions.exclude = [:show, :new]
117
+ end
108
118
  end
109
119
  @exclude_controller = NewExcludeController.new
110
120
  class NewOnlyController < MockController
111
- qadmin :only => [:index, :show]
121
+ qadmin :model_name => 'Item', :available_actions => {:only => [:index, :show]}
112
122
  end
113
123
  @only_controller = NewOnlyController.new
114
124
  end
@@ -126,7 +136,7 @@ class TestQadminController < Test::Unit::TestCase
126
136
  end
127
137
 
128
138
  should "set model name independently" do
129
- assert_equal 'NewOnly', @only_controller.send(:model_name)
139
+ assert_equal 'Item', @only_controller.send(:model_name)
130
140
  assert_equal 'NewExclude', @exclude_controller.send(:model_name)
131
141
  end
132
142
  end
@@ -26,10 +26,20 @@ class TestQadminGenerator < Test::Unit::TestCase
26
26
  end
27
27
  assert_generated_class('test/functional/items_controller_test')
28
28
  assert_directory_exists('app/views/items')
29
- assert_generated_file('app/views/items/_form.erb')
30
- assert_generated_file('app/views/layouts/admin.erb')
29
+ assert_generated_file('app/views/items/_form.html.erb')
30
+ assert_generated_file('app/views/layouts/admin.html.erb')
31
31
  assert_directory_exists('public/images/admin/')
32
32
  end
33
+
34
+ def test_generator_with_after_scaffold_should_only_generate_test_and_erbs
35
+ name = 'Item'
36
+ run_generator('qadmin', [name, '--after-scaffold'], sources, :destination => APP_ROOT)
37
+ assert_file_does_not_exist('app/controllers/items_controller.rb')
38
+ assert_generated_class('test/functional/items_controller_test')
39
+ assert_generated_file('app/views/items/_form.html.erb')
40
+ assert_generated_file('app/views/items/_item.html.erb')
41
+ assert_file_does_not_exist('app/views/layouts/admin.erb')
42
+ end
33
43
 
34
44
  private
35
45
  def sources
@@ -41,6 +51,11 @@ class TestQadminGenerator < Test::Unit::TestCase
41
51
  "rails_generators"
42
52
  end
43
53
 
54
+ def assert_file_does_not_exist(path)
55
+ assert !File.exist?("#{APP_ROOT}/#{path}"),
56
+ "The file '#{APP_ROOT}/#{path}' should not exist"
57
+ end
58
+
44
59
  def base_files
45
60
  [
46
61
  'public/stylesheets/style.css',
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestQadminOptionSet < Test::Unit::TestCase
4
+
5
+ context "OptionSet" do
6
+ context "initializing" do
7
+ context "with an array" do
8
+ setup do
9
+ @option_set = Qadmin::OptionSet.new([:index, :show, :delete])
10
+ end
11
+
12
+ should "set array as default" do
13
+ assert_equal [:index, :show, :delete], @option_set.default
14
+ end
15
+
16
+ should "return array as current" do
17
+ assert_equal [:index, :show, :delete], @option_set.current
18
+ end
19
+ end
20
+
21
+ context "with only options" do
22
+ setup do
23
+ @option_set = Qadmin::OptionSet.new(:default => [:index, :show, :delete], :exclude => :delete)
24
+ end
25
+
26
+ should "set default with options" do
27
+ assert_equal [:index, :show, :delete], @option_set.default
28
+ end
29
+
30
+ should "set exclude with options" do
31
+ assert_equal [:delete], @option_set.exclude
32
+ end
33
+ end
34
+
35
+ context "with an array and options" do
36
+ setup do
37
+ @option_set = Qadmin::OptionSet.new([:index, :show, :delete], :only => :delete)
38
+ end
39
+
40
+ should "set default as array" do
41
+ assert_equal [:index, :show, :delete], @option_set.default
42
+ end
43
+
44
+ should "set only with options" do
45
+ assert_equal [:delete], @option_set.only
46
+ end
47
+ end
48
+ end
49
+
50
+ context "an Option Set" do
51
+ context "with exclude set" do
52
+ setup do
53
+ @option_set = Qadmin::OptionSet.new(:default => [:index, :show, :delete], :exclude => :delete)
54
+ end
55
+
56
+ should "return current without excludes" do
57
+ assert_equal [:index, :show], @option_set.current
58
+ end
59
+
60
+ should "itterate over current" do
61
+ @option_set.each do |option|
62
+ assert [:index, :show].include?(option)
63
+ end
64
+ end
65
+ end
66
+
67
+ context "with only set" do
68
+ setup do
69
+ @option_set = Qadmin::OptionSet.new(:default => [:index, :show, :delete], :only => [:show, :delete])
70
+ end
71
+
72
+ should "return only as current" do
73
+ assert_equal [:show, :delete], @option_set.current
74
+ end
75
+
76
+ should "itterate over only" do
77
+ @option_set.each do |option|
78
+ assert [:show, :delete].include?(option)
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ end