qadmin 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 (53) hide show
  1. data/History.txt +9 -0
  2. data/LICENSE +20 -0
  3. data/Manifest.txt +52 -0
  4. data/PostInstall.txt +1 -0
  5. data/README.rdoc +39 -0
  6. data/Rakefile +31 -0
  7. data/init.rb +1 -0
  8. data/lib/qadmin.rb +20 -0
  9. data/lib/qadmin/assets/form_builder.rb +36 -0
  10. data/lib/qadmin/configuration.rb +48 -0
  11. data/lib/qadmin/controller.rb +139 -0
  12. data/lib/qadmin/form_builder.rb +23 -0
  13. data/lib/qadmin/helper.rb +128 -0
  14. data/lib/qadmin/option_set.rb +48 -0
  15. data/lib/qadmin/overlay.rb +31 -0
  16. data/lib/qadmin/page_titles.rb +34 -0
  17. data/lib/qadmin/templates.rb +52 -0
  18. data/lib/qadmin/views/content_forms/_attachments_form.erb +0 -0
  19. data/lib/qadmin/views/content_forms/_photos_form.erb +4 -0
  20. data/lib/qadmin/views/content_forms/_videos_form.erb +0 -0
  21. data/lib/qadmin/views/default/edit.erb +12 -0
  22. data/lib/qadmin/views/default/index.erb +9 -0
  23. data/lib/qadmin/views/default/new.erb +12 -0
  24. data/lib/qadmin/views/default/show.erb +7 -0
  25. data/rails/init.rb +5 -0
  26. data/rails_generators/qadmin/USAGE +5 -0
  27. data/rails_generators/qadmin/qadmin_generator.rb +111 -0
  28. data/rails_generators/qadmin/templates/_form.html.erb +7 -0
  29. data/rails_generators/qadmin/templates/_instance.html.erb +8 -0
  30. data/rails_generators/qadmin/templates/controller.rb +6 -0
  31. data/rails_generators/qadmin/templates/functional_test.rb +114 -0
  32. data/rails_generators/qadmin/templates/images/icon_asc.gif +0 -0
  33. data/rails_generators/qadmin/templates/images/icon_desc.gif +0 -0
  34. data/rails_generators/qadmin/templates/images/icon_destroy.png +0 -0
  35. data/rails_generators/qadmin/templates/images/icon_edit.png +0 -0
  36. data/rails_generators/qadmin/templates/images/icon_export.png +0 -0
  37. data/rails_generators/qadmin/templates/images/icon_find.png +0 -0
  38. data/rails_generators/qadmin/templates/images/icon_import.png +0 -0
  39. data/rails_generators/qadmin/templates/images/icon_list.png +0 -0
  40. data/rails_generators/qadmin/templates/images/icon_new.png +0 -0
  41. data/rails_generators/qadmin/templates/images/icon_next.gif +0 -0
  42. data/rails_generators/qadmin/templates/images/icon_prev.gif +0 -0
  43. data/rails_generators/qadmin/templates/images/icon_show.png +0 -0
  44. data/rails_generators/qadmin/templates/images/icon_sort.png +0 -0
  45. data/rails_generators/qadmin/templates/images/indicator_medium.gif +0 -0
  46. data/rails_generators/qadmin/templates/layout.html.erb +45 -0
  47. data/rails_generators/qadmin/templates/style.css +683 -0
  48. data/test/test_generator_helper.rb +29 -0
  49. data/test/test_helper.rb +83 -0
  50. data/test/test_qadmin_controller.rb +148 -0
  51. data/test/test_qadmin_generator.rb +76 -0
  52. data/test/test_qadmin_option_set.rb +86 -0
  53. metadata +162 -0
@@ -0,0 +1,29 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+ rescue LoadError
4
+ require 'test/unit'
5
+ end
6
+ require 'fileutils'
7
+
8
+ # Must set before requiring generator libs.
9
+ TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
10
+ PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
11
+ app_root = File.join(TMP_ROOT, PROJECT_NAME)
12
+ if defined?(APP_ROOT)
13
+ APP_ROOT.replace(app_root)
14
+ else
15
+ APP_ROOT = app_root
16
+ end
17
+ # if defined?(RAILS_ROOT)
18
+ # RAILS_ROOT.replace(app_root)
19
+ # else
20
+ # RAILS_ROOT = app_root
21
+ # end
22
+
23
+ begin
24
+ require 'rubigen'
25
+ rescue LoadError
26
+ require 'rubygems'
27
+ require 'rubigen'
28
+ end
29
+ require 'rubigen/helpers/generator_test_helper'
@@ -0,0 +1,83 @@
1
+ require 'rubygems'
2
+ require 'stringio'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'shoulda'
6
+
7
+ require File.dirname(__FILE__) + '/../lib/qadmin'
8
+
9
+
10
+ # mock AR::BASE
11
+ module ActiveRecord
12
+ class Base
13
+ class << self
14
+ attr_accessor :pluralize_table_names
15
+
16
+ def protected_attributes
17
+ []
18
+ end
19
+
20
+ def column_names
21
+ ['id'] #content_columns.collect {|c| c.name }
22
+ end
23
+
24
+ end
25
+ self.pluralize_table_names = true
26
+ end
27
+ end
28
+
29
+
30
+
31
+ class MockColumn
32
+ attr_accessor :name, :type
33
+
34
+ def initialize(name, type)
35
+ self.name = name
36
+ self.type = type
37
+ end
38
+
39
+ def human_name
40
+ name.to_s.humanize
41
+ end
42
+
43
+ def default
44
+ nil
45
+ end
46
+ end
47
+
48
+ class Item < ActiveRecord::Base
49
+
50
+ class << self
51
+
52
+ def content_columns
53
+ columns = {
54
+ :name => :string,
55
+ :sku => :string,
56
+ :description => :text,
57
+ :made_at => :datetime,
58
+ :price => :float,
59
+ :created_at => :datetime,
60
+ :updated_at => :datetime
61
+ }
62
+ columns.collect do |name, type|
63
+ MockColumn.new(name, type)
64
+ end
65
+ end
66
+
67
+ def column_names
68
+ [] #content_columns.collect {|c| c.name }
69
+ end
70
+ end
71
+ end
72
+
73
+ class MockController
74
+ class << self
75
+ def append_view_path(paths)
76
+ end
77
+
78
+ def helper_method(*args)
79
+ end
80
+ end
81
+
82
+ extend Qadmin::Controller::Macros
83
+ end
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestQadminController < Test::Unit::TestCase
4
+
5
+ protected
6
+ def crud_actions
7
+ [:index, :show, :new, :create, :edit, :update, :destroy]
8
+ end
9
+
10
+ def assert_defines_actions(*actions)
11
+ [actions].flatten.each do |action|
12
+ assert @controller.respond_to?(action), "Should define ##{action}"
13
+ end
14
+ end
15
+
16
+ def assert_does_not_define_actions(*actions)
17
+ [actions].flatten.each do |action|
18
+ assert !@controller.respond_to?(action), "Should not define ##{action}"
19
+ end
20
+ end
21
+ public
22
+
23
+ context "QadminController" do
24
+ context "Macros" do
25
+ context "#qadmin" do
26
+
27
+ context "with no options" do
28
+ setup do
29
+ class ::NoOption < ActiveRecord::Base; end
30
+ class NoOptionsController < MockController
31
+ qadmin
32
+ end
33
+ @controller = NoOptionsController.new
34
+ end
35
+
36
+ should "define all CRUD actions" do
37
+ assert_defines_actions(crud_actions)
38
+ end
39
+
40
+ should "set qadmin configuration" do
41
+ assert @controller.send(:qadmin_configuration).is_a?(Qadmin::Configuration)
42
+ end
43
+
44
+ should "set model_name from controller name" do
45
+ assert_equal 'NoOption', @controller.send(:model_name)
46
+ end
47
+
48
+ should "set model_instance_name to underscored version" do
49
+ assert_equal 'no_option', @controller.send(:model_instance_name)
50
+ end
51
+
52
+ should "set human_name to model.humanize" do
53
+ assert_equal 'No option', @controller.send(:model_human_name)
54
+ end
55
+ end
56
+
57
+ context "with hashed options" do
58
+ context "with :exclude" do
59
+ setup do
60
+ class ::Exclude < ActiveRecord::Base; end
61
+ class ExcludeController < MockController
62
+ qadmin :available_actions => {:exclude => [:show, :destroy]}
63
+ end
64
+ @controller = ExcludeController.new
65
+ end
66
+
67
+ should "define CRUD actions" do
68
+ assert_defines_actions(crud_actions - [:show, :destroy])
69
+ end
70
+
71
+ should "not define actions in exclude" do
72
+ assert_does_not_define_actions([:show, :destroy])
73
+ end
74
+ end
75
+
76
+ context "with :only" do
77
+ setup do
78
+ class ::Only < ActiveRecord::Base; end
79
+ class OnlyController < MockController
80
+ qadmin :available_actions => {:only => [:index, :show]}
81
+ end
82
+ @controller = OnlyController.new
83
+ end
84
+
85
+ should "define CRUD actions" do
86
+ assert_defines_actions(:index, :show)
87
+ end
88
+
89
+ should "not define actions in exclude" do
90
+ assert_does_not_define_actions(crud_actions - [:index, :show])
91
+ end
92
+ end
93
+
94
+ context "with :model_name" do
95
+ should "set #model_name" do
96
+
97
+ end
98
+ end
99
+
100
+ context "with :human_name" do
101
+
102
+ should "set the human name" do
103
+
104
+ end
105
+
106
+ should "not effect the existing model name" do
107
+
108
+ end
109
+ end
110
+
111
+ context "with two instances in different controllers" do
112
+ setup do
113
+ class ::NewExclude < ActiveRecord::Base; end
114
+ class NewExcludeController < MockController
115
+ qadmin do |config|
116
+ config.available_actions.exclude = [:show, :new]
117
+ end
118
+ end
119
+ @exclude_controller = NewExcludeController.new
120
+ class NewOnlyController < MockController
121
+ qadmin :model_name => 'Item', :available_actions => {:only => [:index, :show]}
122
+ end
123
+ @only_controller = NewOnlyController.new
124
+ end
125
+
126
+ should "not include actions for :exclude" do
127
+ @controller = @exclude_controller
128
+ assert_does_not_define_actions(:show, :new)
129
+ assert_defines_actions(crud_actions - [:show, :new])
130
+ end
131
+
132
+ should "include actions for :only" do
133
+ @controller = @only_controller
134
+ assert_does_not_define_actions(crud_actions - [:index, :show])
135
+ assert_defines_actions([:index, :show])
136
+ end
137
+
138
+ should "set model name independently" do
139
+ assert_equal 'Item', @only_controller.send(:model_name)
140
+ assert_equal 'NewExclude', @exclude_controller.send(:model_name)
141
+ end
142
+ end
143
+ end
144
+
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,76 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+ require 'rails_generator'
4
+
5
+ class TestQadminGenerator < Test::Unit::TestCase
6
+ include RubiGen::GeneratorTestHelper
7
+
8
+ def setup
9
+ bare_setup
10
+ base_files.each do |file|
11
+ full_path = File.join(APP_ROOT, file)
12
+ FileUtils.mkdir_p(File.dirname(full_path))
13
+ File.open(full_path, 'w') {|f| f << '' }
14
+ end
15
+ end
16
+
17
+ def teardown
18
+ bare_teardown
19
+ end
20
+
21
+ def test_generator_with_model_without_options
22
+ name = 'Item'
23
+ run_generator('qadmin', [name], sources, :destination => APP_ROOT)
24
+ assert_generated_class('app/controllers/items_controller') do |body|
25
+ assert_match(/qadmin/, body)
26
+ end
27
+ assert_generated_class('test/functional/items_controller_test')
28
+ assert_directory_exists('app/views/items')
29
+ assert_generated_file('app/views/items/_form.html.erb')
30
+ assert_generated_file('app/views/layouts/admin.html.erb')
31
+ assert_directory_exists('public/images/admin/')
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
43
+
44
+ private
45
+ def sources
46
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
47
+ ]
48
+ end
49
+
50
+ def generator_path
51
+ "rails_generators"
52
+ end
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
+
59
+ def base_files
60
+ [
61
+ 'public/stylesheets/style.css',
62
+ 'app/views/layouts/main.erb',
63
+ 'config/routes.rb'
64
+ ]
65
+ end
66
+
67
+ def silence_generator
68
+ logger_original = Rails::Generator::Base.logger
69
+ myout = StringIO.new
70
+ Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(myout)
71
+ yield if block_given?
72
+ Rails::Generator::Base.logger = logger_original
73
+ myout.string
74
+ end
75
+
76
+ end
@@ -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
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qadmin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Quint
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-22 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: restful_query
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.3
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: Shoulda
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.0
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.8.0
64
+ version:
65
+ description: An [almost] one command solution for adding admin interfaces/resources to a Rails app.
66
+ email:
67
+ - aaron@quirkey.com
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - PostInstall.txt
76
+ - README.rdoc
77
+ files:
78
+ - History.txt
79
+ - LICENSE
80
+ - Manifest.txt
81
+ - PostInstall.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - init.rb
85
+ - lib/qadmin.rb
86
+ - lib/qadmin/assets/form_builder.rb
87
+ - lib/qadmin/configuration.rb
88
+ - lib/qadmin/controller.rb
89
+ - lib/qadmin/form_builder.rb
90
+ - lib/qadmin/helper.rb
91
+ - lib/qadmin/option_set.rb
92
+ - lib/qadmin/overlay.rb
93
+ - lib/qadmin/page_titles.rb
94
+ - lib/qadmin/templates.rb
95
+ - lib/qadmin/views/content_forms/_attachments_form.erb
96
+ - lib/qadmin/views/content_forms/_photos_form.erb
97
+ - lib/qadmin/views/content_forms/_videos_form.erb
98
+ - lib/qadmin/views/default/edit.erb
99
+ - lib/qadmin/views/default/index.erb
100
+ - lib/qadmin/views/default/new.erb
101
+ - lib/qadmin/views/default/show.erb
102
+ - rails/init.rb
103
+ - rails_generators/qadmin/USAGE
104
+ - rails_generators/qadmin/qadmin_generator.rb
105
+ - rails_generators/qadmin/templates/_form.html.erb
106
+ - rails_generators/qadmin/templates/_instance.html.erb
107
+ - rails_generators/qadmin/templates/controller.rb
108
+ - rails_generators/qadmin/templates/functional_test.rb
109
+ - rails_generators/qadmin/templates/images/icon_asc.gif
110
+ - rails_generators/qadmin/templates/images/icon_desc.gif
111
+ - rails_generators/qadmin/templates/images/icon_destroy.png
112
+ - rails_generators/qadmin/templates/images/icon_edit.png
113
+ - rails_generators/qadmin/templates/images/icon_export.png
114
+ - rails_generators/qadmin/templates/images/icon_find.png
115
+ - rails_generators/qadmin/templates/images/icon_import.png
116
+ - rails_generators/qadmin/templates/images/icon_list.png
117
+ - rails_generators/qadmin/templates/images/icon_new.png
118
+ - rails_generators/qadmin/templates/images/icon_next.gif
119
+ - rails_generators/qadmin/templates/images/icon_prev.gif
120
+ - rails_generators/qadmin/templates/images/icon_show.png
121
+ - rails_generators/qadmin/templates/images/icon_sort.png
122
+ - rails_generators/qadmin/templates/images/indicator_medium.gif
123
+ - rails_generators/qadmin/templates/layout.html.erb
124
+ - rails_generators/qadmin/templates/style.css
125
+ - test/test_generator_helper.rb
126
+ - test/test_helper.rb
127
+ - test/test_qadmin_controller.rb
128
+ - test/test_qadmin_generator.rb
129
+ - test/test_qadmin_option_set.rb
130
+ has_rdoc: true
131
+ homepage: http://github.com/quirkey/qadmin
132
+ post_install_message: PostInstall.txt
133
+ rdoc_options:
134
+ - --main
135
+ - README.rdoc
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: "0"
143
+ version:
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: "0"
149
+ version:
150
+ requirements: []
151
+
152
+ rubyforge_project: quirkey
153
+ rubygems_version: 1.3.1
154
+ signing_key:
155
+ specification_version: 2
156
+ summary: An [almost] one command solution for adding admin interfaces/resources to a Rails app.
157
+ test_files:
158
+ - test/test_generator_helper.rb
159
+ - test/test_helper.rb
160
+ - test/test_qadmin_controller.rb
161
+ - test/test_qadmin_generator.rb
162
+ - test/test_qadmin_option_set.rb