rails_db_admin 2.0.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 (69) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.md +5 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/rails_db_admin/application.js +9 -0
  5. data/app/assets/stylesheets/rails_db_admin/application.css +7 -0
  6. data/app/controllers/rails_db_admin/erp_app/desktop/base_controller.rb +182 -0
  7. data/app/controllers/rails_db_admin/erp_app/desktop/queries_controller.rb +173 -0
  8. data/app/helpers/rails_db_admin/application_helper.rb +4 -0
  9. data/app/views/layouts/application.html.erb +14 -0
  10. data/app/views/layouts/rails_db_admin/application.html.erb +14 -0
  11. data/config/initializers/rails_db_admin.rb +4 -0
  12. data/config/routes.rb +4 -0
  13. data/db/data_migrations/20110816005525_rails_db_admin_application.rb +31 -0
  14. data/lib/rails_db_admin.rb +15 -0
  15. data/lib/rails_db_admin/config.rb +27 -0
  16. data/lib/rails_db_admin/connection_handler.rb +17 -0
  17. data/lib/rails_db_admin/engine.rb +11 -0
  18. data/lib/rails_db_admin/extjs.rb +2 -0
  19. data/lib/rails_db_admin/extjs/json_column_builder.rb +139 -0
  20. data/lib/rails_db_admin/extjs/json_data_builder.rb +82 -0
  21. data/lib/rails_db_admin/query_support.rb +72 -0
  22. data/lib/rails_db_admin/table_support.rb +147 -0
  23. data/lib/rails_db_admin/version.rb +3 -0
  24. data/lib/tasks/rails_db_admin_tasks.rake +4 -0
  25. data/public/images/icons/rails_db_admin/rails_db_admin_16x16.png +0 -0
  26. data/public/images/icons/rails_db_admin/rails_db_admin_24x24.png +0 -0
  27. data/public/images/icons/rails_db_admin/rails_db_admin_32x32.png +0 -0
  28. data/public/images/icons/rails_db_admin/rails_db_admin_48x48.png +0 -0
  29. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/database_combo.js +52 -0
  30. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/module.js +429 -0
  31. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/queries_tree_menu.js +86 -0
  32. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +206 -0
  33. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/readonly_table_data_grid.js +27 -0
  34. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/tables_tree_menu.js +87 -0
  35. data/public/stylesheets/erp_app/desktop/applications/rails_db_admin/rails_db_admin.css +10 -0
  36. data/spec/controllers/rails_db_admin/base_controller_spec.rb +481 -0
  37. data/spec/controllers/rails_db_admin/queries_controller_spec.rb +134 -0
  38. data/spec/dummy/Rakefile +7 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  42. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  44. data/spec/dummy/config.ru +4 -0
  45. data/spec/dummy/config/application.rb +45 -0
  46. data/spec/dummy/config/boot.rb +10 -0
  47. data/spec/dummy/config/database.yml +14 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/cucumber.rb +3 -0
  50. data/spec/dummy/config/environments/spec.rb +27 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/inflections.rb +10 -0
  53. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  54. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  55. data/spec/dummy/config/initializers/session_store.rb +8 -0
  56. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  57. data/spec/dummy/config/locales/en.yml +5 -0
  58. data/spec/dummy/config/routes.rb +5 -0
  59. data/spec/dummy/public/404.html +26 -0
  60. data/spec/dummy/public/422.html +26 -0
  61. data/spec/dummy/public/500.html +26 -0
  62. data/spec/dummy/public/favicon.ico +0 -0
  63. data/spec/dummy/script/rails +6 -0
  64. data/spec/lib/rails_db_admin/extjs/json_column_builder_spec.rb +206 -0
  65. data/spec/lib/rails_db_admin/extjs/json_data_builder_spec.rb +201 -0
  66. data/spec/lib/rails_db_admin/query_support_spec.rb +40 -0
  67. data/spec/lib/rails_db_admin/table_support_spec.rb +349 -0
  68. data/spec/spec_helper.rb +60 -0
  69. metadata +183 -0
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,206 @@
1
+ require "spec_helper"
2
+
3
+ describe RailsDbAdmin::Extjs::JsonColumnBuilder do
4
+
5
+ before(:each) do
6
+ @connection_class = RailsDbAdmin::ConnectionHandler.create_connection_class("spec")
7
+ @connection = @connection_class.connection
8
+ end
9
+
10
+ describe "build_grid_columns" do
11
+
12
+ it "should return an array of hashes to setup a ExtJS Grid column object" do
13
+
14
+ expected_result =[{:header=>"id", :type=>"number", :dataIndex=>"id", :width=>150
15
+ },
16
+ {:header=>"parent_id",
17
+ :type=>"number",
18
+ :dataIndex=>"parent_id",
19
+ :width=>150,
20
+ :editor=>{:xtype=>"textfield"}
21
+ },
22
+ {:header=>"lft",
23
+ :type=>"number",
24
+ :dataIndex=>"lft",
25
+ :width=>150,
26
+ :editor=>{:xtype=>"textfield"}
27
+ },
28
+ {:header=>"rgt",
29
+ :type=>"number",
30
+ :dataIndex=>"rgt",
31
+ :width=>150,
32
+ :editor=>{:xtype=>"textfield"}
33
+ },
34
+ {:header=>"description",
35
+ :type=>"string",
36
+ :dataIndex=>"description",
37
+ :width=>150,
38
+ :editor=>{:xtype=>"textfield"}
39
+ },
40
+ {:header=>"comments",
41
+ :type=>"string",
42
+ :dataIndex=>"comments",
43
+ :width=>150,
44
+ :editor=>{:xtype=>"textfield"}
45
+ },
46
+ {:header=>"internal_identifier",
47
+ :type=>"string",
48
+ :dataIndex=>"internal_identifier",
49
+ :width=>150,
50
+ :editor=>{:xtype=>"textfield"}
51
+ },
52
+ {:header=>"external_identifier",
53
+ :type=>"string",
54
+ :dataIndex=>"external_identifier",
55
+ :width=>150,
56
+ :editor=>{:xtype=>"textfield"}
57
+ },
58
+ {:header=>"external_id_source",
59
+ :type=>"string",
60
+ :dataIndex=>"external_id_source",
61
+ :width=>150,
62
+ :editor=>{:xtype=>"textfield"}
63
+ },
64
+ {:header=>"created_at",
65
+ :type=>"date",
66
+ :dataIndex=>"created_at",
67
+ :width=>150
68
+ },
69
+ {:header=>"updated_at",
70
+ :type=>"date",
71
+ :dataIndex=>"updated_at",
72
+ :width=>150
73
+ }]
74
+
75
+ result = RailsDbAdmin::Extjs::JsonColumnBuilder.build_grid_columns(
76
+ @connection.columns("role_types"))
77
+
78
+ result.should eq(expected_result)
79
+ end
80
+
81
+ it "should add a fake_id column to the result if I pass true as the second param" do
82
+
83
+ expected_result =[{:header=>"id",
84
+ :type=>"number",
85
+ :dataIndex=>"id",
86
+ :width=>150},
87
+ {:header=>"parent_id",
88
+ :type=>"number",
89
+ :dataIndex=>"parent_id",
90
+ :width=>150,
91
+ :editor=>{:xtype=>"textfield"}
92
+ },
93
+ {:header=>"lft",
94
+ :type=>"number",
95
+ :dataIndex=>"lft",
96
+ :width=>150,
97
+ :editor=>{:xtype=>"textfield"}
98
+ },
99
+ {:header=>"rgt",
100
+ :type=>"number",
101
+ :dataIndex=>"rgt",
102
+ :width=>150,
103
+ :editor=>{:xtype=>"textfield"}
104
+ },
105
+ {:header=>"description",
106
+ :type=>"string",
107
+ :dataIndex=>"description",
108
+ :width=>150,
109
+ :editor=>{:xtype=>"textfield"}
110
+ },
111
+ {:header=>"comments",
112
+ :type=>"string",
113
+ :dataIndex=>"comments",
114
+ :width=>150,
115
+ :editor=>{:xtype=>"textfield"}
116
+ },
117
+ {:header=>"internal_identifier",
118
+ :type=>"string",
119
+ :dataIndex=>"internal_identifier",
120
+ :width=>150,
121
+ :editor=>{:xtype=>"textfield"}
122
+ },
123
+ {:header=>"external_identifier",
124
+ :type=>"string",
125
+ :dataIndex=>"external_identifier",
126
+ :width=>150,
127
+ :editor=>{:xtype=>"textfield"}
128
+ },
129
+ {:header=>"external_id_source",
130
+ :type=>"string",
131
+ :dataIndex=>"external_id_source",
132
+ :width=>150,
133
+ :editor=>{:xtype=>"textfield"}
134
+ },
135
+ {:header=>"created_at",
136
+ :type=>"date",
137
+ :dataIndex=>"created_at",
138
+ :width=>150
139
+ },
140
+ {:header=>"updated_at",
141
+ :type=>"date",
142
+ :dataIndex=>"updated_at",
143
+ :width=>150
144
+ },
145
+ {:header=>"fake_id",
146
+ :type=>"number",
147
+ :dataIndex=>"fake_id",
148
+ :hidden=>true}]
149
+
150
+ result = RailsDbAdmin::Extjs::JsonColumnBuilder.build_grid_columns(
151
+ @connection.columns("role_types"), true)
152
+
153
+ result.should eq(expected_result)
154
+ end
155
+
156
+ end
157
+
158
+ describe "build_store_fields" do
159
+
160
+ it "should return an array of hashes that will setup the fields config for an ExtJS grid" do
161
+
162
+ expected_result = [{:name=>"id"},
163
+ {:name=>"parent_id"},
164
+ {:name=>"lft"},
165
+ {:name=>"rgt"},
166
+ {:name=>"description"},
167
+ {:name=>"comments"},
168
+ {:name=>"internal_identifier"},
169
+ {:name=>"external_identifier"},
170
+ {:name=>"external_id_source"},
171
+ {:name=>"created_at"},
172
+ {:name=>"updated_at"}]
173
+
174
+ result = RailsDbAdmin::Extjs::JsonColumnBuilder.build_store_fields(
175
+ @connection.columns("role_types"))
176
+
177
+ result.should eq(expected_result)
178
+
179
+ end
180
+
181
+ it "should add a fake_id field to the result if I pass true as the second param" do
182
+
183
+ expected_result = [{:name=>"id"},
184
+ {:name=>"parent_id"},
185
+ {:name=>"lft"},
186
+ {:name=>"rgt"},
187
+ {:name=>"description"},
188
+ {:name=>"comments"},
189
+ {:name=>"internal_identifier"},
190
+ {:name=>"external_identifier"},
191
+ {:name=>"external_id_source"},
192
+ {:name=>"created_at"},
193
+ {:name=>"updated_at"},
194
+ {:name=>"fake_id"}]
195
+
196
+ result = RailsDbAdmin::Extjs::JsonColumnBuilder.build_store_fields(
197
+ @connection.columns("role_types"),true)
198
+
199
+ result.should eq(expected_result)
200
+
201
+ end
202
+
203
+ end
204
+
205
+
206
+ end
@@ -0,0 +1,201 @@
1
+ require "spec_helper"
2
+
3
+ describe RailsDbAdmin::Extjs::JsonDataBuilder do
4
+
5
+ #preconditions
6
+ before(:each) do
7
+ @connection_class = double(ActiveRecord::Base)
8
+ @adapter = double(ActiveRecord::ConnectionAdapters::AbstractAdapter)
9
+ @connection_class.should_receive(:connection).and_return(@adapter)
10
+ @instance = RailsDbAdmin::Extjs::JsonDataBuilder.new(@connection_class)
11
+ end
12
+
13
+ describe "build_json_data" do
14
+
15
+ it "should pass well-formed sql to the connection.select_all" do
16
+
17
+ options = {:table => "test_table",
18
+ :offset => 2,
19
+ :limit => 30,
20
+ :order => 'id desc'}
21
+
22
+ sql = "SELECT * FROM \"test_table\" ORDER BY id desc LIMIT 30 OFFSET 2"
23
+
24
+ @instance.should_receive(:get_total_count).and_return(25)
25
+ @adapter.should_receive(:select_all).with(sql).and_return([])
26
+ @adapter.should_receive(:sanitize_limit).with(30).and_return(30)
27
+
28
+ RailsDbAdmin::TableSupport.should_receive(
29
+ :database_rows_to_hash).with([]).and_return([])
30
+ @instance.build_json_data(options)
31
+ end
32
+
33
+ it "should pass well-formed sql to the connection.select_all (string args)" do
34
+
35
+ options = {:table => "test_table",
36
+ :offset => "2",
37
+ :limit => "30",
38
+ :order => 'id desc'}
39
+
40
+ sql = "SELECT * FROM \"test_table\" ORDER BY id desc LIMIT 30 OFFSET 2"
41
+ @adapter.should_receive(:select_all).with(sql).and_return([])
42
+
43
+ @adapter.should_receive(:sanitize_limit).with("30").and_return(30)
44
+
45
+ RailsDbAdmin::TableSupport.should_receive(
46
+ :database_rows_to_hash).with([]).and_return([])
47
+
48
+ @instance.should_receive(:get_total_count).and_return(25)
49
+
50
+ @instance.build_json_data(options)
51
+ end
52
+
53
+ it "should create well-formed sql, only passing :limit, :order options" do
54
+
55
+ options = {:table => "test_table",
56
+ :limit => 30,
57
+ :order => 'id desc'}
58
+
59
+ sql = "SELECT * FROM \"test_table\" ORDER BY id desc LIMIT 30"
60
+ @adapter.should_receive(:select_all).with(sql).and_return([])
61
+
62
+ @adapter.should_receive(:sanitize_limit).with(30).and_return(30)
63
+
64
+ RailsDbAdmin::TableSupport.should_receive(
65
+ :database_rows_to_hash).with([]).and_return([])
66
+
67
+ @instance.should_receive(:get_total_count).and_return(25)
68
+
69
+ @instance.build_json_data(options)
70
+ end
71
+
72
+ it "should create well-formed sql, only passing :limit option" do
73
+
74
+ options = {:table => "test_table",
75
+ :limit => 30}
76
+
77
+ sql = "SELECT * FROM \"test_table\" LIMIT 30"
78
+ @adapter.should_receive(:select_all).with(sql).and_return([])
79
+
80
+ @adapter.should_receive(:sanitize_limit).with(30).and_return(30)
81
+
82
+ @instance.should_receive(:get_total_count).and_return(25)
83
+
84
+ RailsDbAdmin::TableSupport.should_receive(
85
+ :database_rows_to_hash).with([]).and_return([])
86
+
87
+ @instance.build_json_data(options)
88
+ end
89
+
90
+ it "should create well-formed sql, only passing :order option" do
91
+
92
+ options = {:table => "test_table",
93
+ :order => "id asc"}
94
+
95
+ sql = "SELECT * FROM \"test_table\" ORDER BY id asc"
96
+ @adapter.should_receive(:select_all).with(sql).and_return([])
97
+
98
+ RailsDbAdmin::TableSupport.should_receive(
99
+ :database_rows_to_hash).with([]).and_return([])
100
+
101
+ @instance.should_receive(:get_total_count).and_return(25)
102
+
103
+ @instance.build_json_data(options)
104
+ end
105
+
106
+ it "should create well-formed sql, only passing :table option" do
107
+
108
+ options = {:table => "test_table"}
109
+
110
+ sql = "SELECT * FROM \"test_table\" "
111
+ @adapter.should_receive(:select_all).with(sql).and_return([])
112
+
113
+ RailsDbAdmin::TableSupport.should_receive(
114
+ :database_rows_to_hash).with([]).and_return([])
115
+
116
+ @instance.should_receive(:get_total_count).and_return(25)
117
+
118
+ @instance.build_json_data(options)
119
+ end
120
+
121
+ it "should raise an exception if missing :table option" do
122
+
123
+ options = {:limit => 30}
124
+ expect {@instance.build_json_data(options) }.to raise_error
125
+ end
126
+
127
+ it "should call add_fake_id_col if there's no 'id' col in the result hash" do
128
+
129
+ options = {:table => "test_table",
130
+ :start => 0,
131
+ :limit => 30,
132
+ :order => 'id desc'}
133
+
134
+ sql = "SELECT * FROM \"test_table\" ORDER BY id desc LIMIT 30"
135
+ @adapter.should_receive(:select_all).with(sql).and_return([])
136
+
137
+ test_data = [{"column_a" => "blah1", "column_b" => "blah2"},
138
+ {"column_a" => "blah3", "column_b" => "blah4"}]
139
+
140
+ @adapter.should_receive(:sanitize_limit).with(30).and_return(30)
141
+
142
+ RailsDbAdmin::TableSupport.should_receive(
143
+ :database_rows_to_hash).with([]).and_return(test_data)
144
+ RailsDbAdmin::TableSupport.should_receive(:add_fake_id_col).with(
145
+ test_data).and_return(test_data)
146
+
147
+ @instance.should_receive(:get_total_count).and_return(25)
148
+ @instance.build_json_data(options)
149
+ end
150
+ end
151
+
152
+ describe "get_row_data_no_id" do
153
+
154
+ it "should return a row with a fake_id column added to it" do
155
+
156
+ @table = "preference_options_preference_types"
157
+
158
+ row_hash = {"preference_type_id" => "1",
159
+ "preference_option_id" => "2",
160
+ "created_at" => "2011-10-11 00:54:56.137144",
161
+ "updated_at" => "2011-10-11 00:54:56.137144"}
162
+
163
+ @result = {:preference_type_id => "1",
164
+ :preference_option_id => "2",
165
+ :created_at => "2011-10-11 00:54:56.137144",
166
+ :updated_at => "2011-10-11 00:54:56.137144",
167
+ :fake_id => 1}
168
+
169
+ @rows = [{"preference_type_id" => "1",
170
+ "preference_option_id" => "2",
171
+ "created_at" => "2011-10-11 00:54:56.137144",
172
+ "updated_at" => "2011-10-11 00:54:56.137144"}]
173
+
174
+ @sql = "SELECT * FROM \"preference_options_preference_types\" "\
175
+ "WHERE \"preference_options_preference_types\"."\
176
+ "\"preference_type_id\" = 1 AND "\
177
+ "\"preference_options_preference_types\"."\
178
+ "\"preference_option_id\" = 2 AND "\
179
+ "\"preference_options_preference_types\".\"created_at\" "\
180
+ "= '2011-10-11 00:54:56.137144' AND "\
181
+ "\"preference_options_preference_types\".\"updated_at\" "\
182
+ "= '2011-10-11 00:54:56.137144'"
183
+
184
+ @adapter.should_receive(:select_all).with(@sql).and_return(@rows)
185
+
186
+ returns = @instance.get_row_data_no_id("preference_options_preference_types", row_hash)
187
+ returns.should eq(@result)
188
+ end
189
+ end
190
+
191
+ describe "get_row_data" do
192
+
193
+ it "should send good sql to the connection adapter" do
194
+
195
+ @sql = "SELECT * FROM \"role_types\" WHERE \"role_types\".\"id\" = 3"
196
+
197
+ @adapter.should_receive(:select_all).with(@sql).and_return([])
198
+ returns = @instance.get_row_data("role_types", ['id', 3])
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe RailsDbAdmin::QuerySupport do
4
+
5
+ before(:each) do
6
+ @connection_class = double(ActiveRecord::Base)
7
+ @adapter = double(ActiveRecord::ConnectionAdapters::AbstractAdapter)
8
+ @connection_class.should_receive(:connection).and_return(@adapter)
9
+ @instance = RailsDbAdmin::QuerySupport.new(@connection_class)
10
+ end
11
+
12
+ describe "select_top_fifty" do
13
+
14
+ it "should pass well formed sql to select_all" do
15
+
16
+ @sql = "SELECT * FROM \"test_table\" LIMIT 50"
17
+
18
+ @adapter.should_receive(:select_all).with(@sql).and_return([])
19
+
20
+ @instance.select_top_fifty("test_table")
21
+ end
22
+
23
+ it "should return a sql statement and an array of hashes" do
24
+
25
+ @sql = "SELECT * FROM \"test_table\" LIMIT 50"
26
+
27
+ @return_arry = [{:col_a => "some_val"},
28
+ {:col_a => "some_val2"}]
29
+
30
+ @adapter.should_receive(:select_all).with(@sql).and_return([])
31
+
32
+ RailsDbAdmin::TableSupport.stub(:database_rows_to_hash).
33
+ and_return(@return_arry)
34
+
35
+ sql, records = @instance.select_top_fifty("test_table")
36
+ sql.should eq(@sql)
37
+ records.should eq(@return_arry)
38
+ end
39
+ end
40
+ end