rails_db_admin 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GPL-3-LICENSE +674 -0
- data/README.md +5 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/rails_db_admin/application.js +9 -0
- data/app/assets/stylesheets/rails_db_admin/application.css +7 -0
- data/app/controllers/rails_db_admin/erp_app/desktop/base_controller.rb +182 -0
- data/app/controllers/rails_db_admin/erp_app/desktop/queries_controller.rb +173 -0
- data/app/helpers/rails_db_admin/application_helper.rb +4 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/rails_db_admin/application.html.erb +14 -0
- data/config/initializers/rails_db_admin.rb +4 -0
- data/config/routes.rb +4 -0
- data/db/data_migrations/20110816005525_rails_db_admin_application.rb +31 -0
- data/lib/rails_db_admin.rb +15 -0
- data/lib/rails_db_admin/config.rb +27 -0
- data/lib/rails_db_admin/connection_handler.rb +17 -0
- data/lib/rails_db_admin/engine.rb +11 -0
- data/lib/rails_db_admin/extjs.rb +2 -0
- data/lib/rails_db_admin/extjs/json_column_builder.rb +139 -0
- data/lib/rails_db_admin/extjs/json_data_builder.rb +82 -0
- data/lib/rails_db_admin/query_support.rb +72 -0
- data/lib/rails_db_admin/table_support.rb +147 -0
- data/lib/rails_db_admin/version.rb +3 -0
- data/lib/tasks/rails_db_admin_tasks.rake +4 -0
- data/public/images/icons/rails_db_admin/rails_db_admin_16x16.png +0 -0
- data/public/images/icons/rails_db_admin/rails_db_admin_24x24.png +0 -0
- data/public/images/icons/rails_db_admin/rails_db_admin_32x32.png +0 -0
- data/public/images/icons/rails_db_admin/rails_db_admin_48x48.png +0 -0
- data/public/javascripts/erp_app/desktop/applications/rails_db_admin/database_combo.js +52 -0
- data/public/javascripts/erp_app/desktop/applications/rails_db_admin/module.js +429 -0
- data/public/javascripts/erp_app/desktop/applications/rails_db_admin/queries_tree_menu.js +86 -0
- data/public/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +206 -0
- data/public/javascripts/erp_app/desktop/applications/rails_db_admin/readonly_table_data_grid.js +27 -0
- data/public/javascripts/erp_app/desktop/applications/rails_db_admin/tables_tree_menu.js +87 -0
- data/public/stylesheets/erp_app/desktop/applications/rails_db_admin/rails_db_admin.css +10 -0
- data/spec/controllers/rails_db_admin/base_controller_spec.rb +481 -0
- data/spec/controllers/rails_db_admin/queries_controller_spec.rb +134 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +14 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/cucumber.rb +3 -0
- data/spec/dummy/config/environments/spec.rb +27 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/lib/rails_db_admin/extjs/json_column_builder_spec.rb +206 -0
- data/spec/lib/rails_db_admin/extjs/json_data_builder_spec.rb +201 -0
- data/spec/lib/rails_db_admin/query_support_spec.rb +40 -0
- data/spec/lib/rails_db_admin/table_support_spec.rb +349 -0
- data/spec/spec_helper.rb +60 -0
- metadata +183 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsDbAdmin::QueriesController do
|
4
|
+
|
5
|
+
#handle devise user auth
|
6
|
+
before(:each) do
|
7
|
+
basic_user_auth
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "POST execute_query" do
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
Factory.create(:role_type, :internal_identifier => "execute_query_test_role")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns unsuccessful because of an empty result set" do
|
17
|
+
|
18
|
+
post :queries, {:use_route => :rails_db_admin, :action => "execute_query",
|
19
|
+
:cursor_pos => "0",:sql => "SELECT * FROM relationship_types;"}
|
20
|
+
|
21
|
+
parsed_body = JSON.parse(response.body)
|
22
|
+
parsed_body["success"].should eq(false)
|
23
|
+
parsed_body["exception"].should eq("Empty result set")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not throw exception if there is 1 statement and no semi-colon" do
|
27
|
+
|
28
|
+
post :queries, {:use_route => :rails_db_admin,
|
29
|
+
:action => "execute_query",
|
30
|
+
:cursor_pos => "0",
|
31
|
+
:sql => "SELECT * FROM role_types "\
|
32
|
+
"WHERE internal_identifier"\
|
33
|
+
" = 'execute_query_test_role'"}
|
34
|
+
|
35
|
+
parsed_body = JSON.parse(response.body)
|
36
|
+
parsed_body["success"].should eq(true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should work on multi-line queries" do
|
40
|
+
|
41
|
+
post :queries, {:use_route => :rails_db_admin, :action => "execute_query",
|
42
|
+
:cursor_pos => "1",
|
43
|
+
:sql => "SELECT * FROM role_types \n"\
|
44
|
+
"WHERE internal_identifier ="\
|
45
|
+
"'execute_query_test_role';"}
|
46
|
+
|
47
|
+
parsed_body = JSON.parse(response.body)
|
48
|
+
parsed_body["success"].should eq(true)
|
49
|
+
parsed_body["exception"].should eq(nil)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should work on queries with line count >2" do
|
53
|
+
@sql = "DELETE%20FROM%20preference_options_preference_types"\
|
54
|
+
"%20WHERE%20%0Apreference_type_id%20%3D%203%20AND%20%0"\
|
55
|
+
"Apreference_option_id%20%3D%209%20OR%0Apreference_option_id"\
|
56
|
+
"%20%3D%2010%3B%0A%0ASELECT%20*%20FROM%20preference_"\
|
57
|
+
"options_preference_types%0AORDER%20BY%20preference_type_id%20ASC%3B"
|
58
|
+
|
59
|
+
@sql = CGI::unescape(@sql)
|
60
|
+
@cursor_pos = "6"
|
61
|
+
|
62
|
+
post :queries, {:use_route => :rails_db_admin, :action => "execute_query",
|
63
|
+
:cursor_pos => @cursor_pos,
|
64
|
+
:sql => @sql}
|
65
|
+
|
66
|
+
parsed_body = JSON.parse(response.body)
|
67
|
+
parsed_body["success"].should eq(false)
|
68
|
+
parsed_body["exception"].should eq("Empty result set")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should work on input of multiple queries spanning several lines each " do
|
72
|
+
|
73
|
+
post :queries, {:use_route => :rails_db_admin, :action => "execute_query",
|
74
|
+
:cursor_pos => "1",
|
75
|
+
:sql => "SELECT * FROM role_types \n"\
|
76
|
+
"WHERE internal_identifier = 'execute_query_test_role';\n"\
|
77
|
+
"SELECT * FROM widgets"}
|
78
|
+
|
79
|
+
parsed_body = JSON.parse(response.body)
|
80
|
+
parsed_body["success"].should eq(true)
|
81
|
+
parsed_body["exception"].should eq(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
after(:all) do
|
85
|
+
RoleType.where(:internal_identifier => "execute_query_test_role").destroy_all
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "POST open_and_execute_query" do
|
91
|
+
|
92
|
+
it "should return success" do
|
93
|
+
|
94
|
+
@db_connection_class =
|
95
|
+
RailsDbAdmin::ConnectionHandler.create_connection_class("spec")
|
96
|
+
@query_support = double("RailsDbAdmin::QuerySupport")
|
97
|
+
@query_support.should_receive(:get_query).and_return("SELECT 1 FROM dual;")
|
98
|
+
columns = ["columns_a", "columns_b", "columns_c"]
|
99
|
+
values = ["A", "B", "C"]
|
100
|
+
|
101
|
+
@query_support.should_receive(:execute_sql).and_return([columns, values, nil])
|
102
|
+
RailsDbAdmin::QuerySupport.should_receive(:new).and_return(@query_support)
|
103
|
+
|
104
|
+
post :queries, {:use_route => :rails_db_admin,
|
105
|
+
:action => "open_and_execute_query",
|
106
|
+
:query_name => "some_query"}
|
107
|
+
|
108
|
+
parsed_body = JSON.parse(response.body)
|
109
|
+
parsed_body["success"].should eq(true)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "POST select_top_fifty" do
|
114
|
+
|
115
|
+
|
116
|
+
it "should return true, a sql statement, grid columns & fields, and data" do
|
117
|
+
|
118
|
+
post :queries, {:use_route => :rails_db_admin,
|
119
|
+
:action => "select_top_fifty",
|
120
|
+
:table => "role_types"}
|
121
|
+
|
122
|
+
expected_sql = "SELECT * FROM \"role_types\" LIMIT 50"
|
123
|
+
|
124
|
+
expected_column = {"header"=>"id", "type"=>"number",
|
125
|
+
"dataIndex"=>"id", "width"=>150}
|
126
|
+
|
127
|
+
parsed_body = JSON.parse(response.body)
|
128
|
+
parsed_body["success"].should eq(true)
|
129
|
+
parsed_body["sql"].should eq(expected_sql)
|
130
|
+
parsed_body["columns"][0].should include(expected_column)
|
131
|
+
parsed_body["fields"][0].should include({"name"=>"id"})
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require
|
6
|
+
require "erp_base_erp_svcs"
|
7
|
+
require "erp_tech_svcs"
|
8
|
+
require "erp_app"
|
9
|
+
require "rails_db_admin"
|
10
|
+
|
11
|
+
module Dummy
|
12
|
+
class Application < Rails::Application
|
13
|
+
# Settings in config/environments/* take precedence over those specified here.
|
14
|
+
# Application configuration should go into files in config/initializers
|
15
|
+
# -- all .rb files in that directory are automatically loaded.
|
16
|
+
|
17
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
18
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
19
|
+
|
20
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
21
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
22
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
23
|
+
|
24
|
+
# Activate observers that should always be running.
|
25
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
26
|
+
|
27
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
28
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
29
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
30
|
+
|
31
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
32
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
33
|
+
# config.i18n.default_locale = :de
|
34
|
+
|
35
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
36
|
+
config.encoding = "utf-8"
|
37
|
+
|
38
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
39
|
+
config.filter_parameters += [:password]
|
40
|
+
|
41
|
+
# Enable the asset pipeline
|
42
|
+
config.assets.enabled = true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Warning: The database defined as "test" will be erased and
|
2
|
+
# re-generated from your development database when you run "rake".
|
3
|
+
# Do not set this db to the same as development or production.
|
4
|
+
spec:
|
5
|
+
adapter: sqlite3
|
6
|
+
database: db/spec.sqlite3
|
7
|
+
pool: 5
|
8
|
+
timeout: 5000
|
9
|
+
|
10
|
+
cucumber:
|
11
|
+
adapter: sqlite3
|
12
|
+
database: db/cucumber.sqlite3
|
13
|
+
pool: 5
|
14
|
+
timeout: 5000
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Do not compress assets
|
26
|
+
config.assets.compress = false
|
27
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = 'ae0d58840f73a49e40850c9d815a6a135e169865cdb8721cec7f335a738af09f3483de0f99d7c131f8fdecf2d8b508f8fd5e2e33c8d0565dcc9030eadb227695'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActionController::Base.wrap_parameters :format => [:json]
|
8
|
+
|
9
|
+
# Disable root element in JSON by default.
|
10
|
+
if defined?(ActiveRecord)
|
11
|
+
ActiveRecord::Base.include_root_in_json = false
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|