├── .gitignore
├── .travis.yml
├── Gemfile
├── MIT-LICENSE
├── README.md
├── Rakefile
├── app
├── assets
│ ├── images
│ │ └── rails_db_info
│ │ │ └── .keep
│ ├── javascripts
│ │ └── rails_db_info
│ │ │ ├── application.js
│ │ │ └── tables.js
│ └── stylesheets
│ │ └── rails_db_info
│ │ ├── application.css
│ │ └── tables.css
├── controllers
│ └── rails_db_info
│ │ ├── application_controller.rb
│ │ └── tables_controller.rb
├── helpers
│ └── rails_db_info
│ │ ├── application_helper.rb
│ │ └── tables_helper.rb
└── views
│ ├── layouts
│ └── rails_db_info
│ │ └── application.html.erb
│ └── rails_db_info
│ └── tables
│ ├── _header.html.erb
│ ├── entries.html.erb
│ ├── index.html.erb
│ └── show.html.erb
├── bin
└── rails
├── config
└── routes.rb
├── gemfiles
├── rails_3-1-stable.gemfile
├── rails_3-2-stable.gemfile
├── rails_4-0-stable.gemfile
├── rails_4-1-stable.gemfile
├── rails_4-2-stable.gemfile
└── ruby-1.8.7.gemfile
├── lib
├── rails
│ └── routes.rb
├── rails_db_info.rb
├── rails_db_info
│ ├── engine.rb
│ ├── table.rb
│ ├── table_entries.rb
│ └── version.rb
└── tasks
│ └── rails_db_info_tasks.rake
├── rails_db_info.gemspec
└── test
├── controllers
└── rails_db_info
│ └── tables_controller_test.rb
├── dummy
├── README.rdoc
├── Rakefile
├── app
│ ├── assets
│ │ ├── images
│ │ │ └── .keep
│ │ ├── javascripts
│ │ │ └── application.js
│ │ └── stylesheets
│ │ │ └── application.css
│ ├── controllers
│ │ ├── application_controller.rb
│ │ └── concerns
│ │ │ └── .keep
│ ├── helpers
│ │ └── application_helper.rb
│ ├── mailers
│ │ └── .keep
│ ├── models
│ │ ├── .keep
│ │ ├── concerns
│ │ │ └── .keep
│ │ └── user.rb
│ └── views
│ │ └── layouts
│ │ └── application.html.erb
├── bin
│ ├── bundle
│ ├── rails
│ └── rake
├── config.ru
├── config
│ ├── application.rb
│ ├── boot.rb
│ ├── database.yml
│ ├── environment.rb
│ ├── environments
│ │ ├── development.rb
│ │ ├── production.rb
│ │ └── test.rb
│ ├── initializers
│ │ ├── backtrace_silencers.rb
│ │ ├── filter_parameter_logging.rb
│ │ ├── inflections.rb
│ │ ├── mime_types.rb
│ │ ├── secret_token.rb
│ │ ├── session_store.rb
│ │ └── wrap_parameters.rb
│ ├── locales
│ │ └── en.yml
│ └── routes.rb
├── db
│ ├── migrate
│ │ └── 20130819203338_create_users.rb
│ └── schema.rb
├── lib
│ └── assets
│ │ └── .keep
├── log
│ └── .keep
├── public
│ ├── 404.html
│ ├── 422.html
│ ├── 500.html
│ └── favicon.ico
└── test
│ ├── fixtures
│ └── users.yml
│ └── models
│ └── user_test.rb
├── helpers
└── rails_db_info
│ └── tables_helper_test.rb
├── integration
├── catch_all_routes_test.rb
└── navigation_test.rb
├── rails_db_info_test.rb
└── test_helper.rb
/.gitignore:
--------------------------------------------------------------------------------
1 | .bundle/
2 | .ruby-version
3 | log/*.log
4 | pkg/
5 | test/dummy/db/*.sqlite3
6 | test/dummy/db/*.sqlite3-journal
7 | test/dummy/log/*.log
8 | test/dummy/tmp/
9 | test/dummy/.sass-cache
10 | Gemfile.lock
11 | gemfiles/*.lock
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 |
3 | cache: bundler
4 |
5 | rvm:
6 | - 1.8.7
7 | - 1.9.3
8 | - 2.2.2
9 |
10 | gemfile:
11 | - gemfiles/ruby-1.8.7.gemfile
12 | - gemfiles/rails_3-1-stable.gemfile
13 | - gemfiles/rails_3-2-stable.gemfile
14 | - gemfiles/rails_4-0-stable.gemfile
15 | - gemfiles/rails_4-1-stable.gemfile
16 | - gemfiles/rails_4-2-stable.gemfile
17 |
18 | env:
19 | - "CATCH_ALL_ROUTE=true"
20 | - "DB=mysql"
21 | - "DB=postgresql"
22 | - "DB=sqlite"
23 |
24 | before_script:
25 | - mysql -e 'create database rails_db_info_test;'
26 | - psql -c 'create database rails_db_info_test;' -U postgres
27 |
28 | script:
29 | - RAILS_ENV=test bundle exec rake db:migrate --trace
30 | - bundle exec rake
31 |
32 | matrix:
33 | exclude:
34 | - rvm: 1.8.7
35 | - rvm: 1.9.3
36 | - gemfile: gemfiles/ruby-1.8.7.gemfile
37 | - env: "CATCH_ALL_ROUTE=true"
38 | - env: "DB=mysql"
39 | - env: "DB=sqlite"
40 |
41 | include:
42 | - rvm: 1.8.7
43 | gemfile: gemfiles/ruby-1.8.7.gemfile
44 | env: "DB=postgresql"
45 | - rvm: 1.9.3
46 | gemfile: gemfiles/rails_4-2-stable.gemfile
47 | env: "DB=postgresql"
48 | - rvm: 2.2.2
49 | env: "CATCH_ALL_ROUTE=true"
50 | gemfile: gemfiles/rails_4-2-stable.gemfile
51 | - rvm: 2.2.2
52 | env: "DB=mysql"
53 | gemfile: gemfiles/rails_4-2-stable.gemfile
54 | - rvm: 2.2.2
55 | env: "DB=sqlite"
56 | gemfile: gemfiles/rails_4-2-stable.gemfile
57 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | # Declare your gem's dependencies in rails_db_info.gemspec.
4 | # Bundler will treat runtime dependencies like base dependencies, and
5 | # development dependencies will be added by default to the :development group.
6 | gemspec :path => File.expand_path("../.", __FILE__)
7 |
8 |
--------------------------------------------------------------------------------
/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2013 Vlado Cingel
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rails database info [](https://travis-ci.org/vlado/rails_db_info) [](https://codeclimate.com/github/vlado/rails_db_info) [](http://badge.fury.io/rb/rails_db_info)
2 |
3 | Adds an html endpoint to your Rails application which will give you a quick display of your database schema and contents for reference at `http://localhost:3000/rails/info/db`
4 |
5 | 
6 |
7 | 
8 |
9 | ## Install
10 |
11 | Add this to the development group in your Gemfile
12 |
13 | ```ruby
14 | group :development do
15 | gem 'rails_db_info'
16 | end
17 | ```
18 |
19 | Run `bundle install`
20 |
21 | Visit `http://localhost:3000/rails/info/db` and you will see your database schema and values.
22 |
23 | ### For users of catch-all routes
24 |
25 | If (and only if) you have catch all routes like `get '*path' => 'your_controller#your_action'` in your app already, you can manually add rails_db_info to your routes (config/routes.rb) **before** the catch-all routes like this.
26 |
27 | ```ruby
28 | if Rails.env.development?
29 | mount_rails_db_info as: 'rails_db_info_engine'
30 | # mount_rails_db_info is enough for rails version < 4
31 | end
32 | get '*path' => 'your_controller#your_action'
33 | ```
34 |
35 | ## Why?
36 |
37 | I was using [Annotate](https://github.com/ctran/annotate_models) to annotate my models with schema info. When I saw [Sextant](https://github.com/schneems/sextant) I got an idea to create something similar for database and the rest is history :)
38 |
39 | ## Todo / Ideas
40 |
41 | - [ ] Improve CSS
42 | - [ ] Add small bar (like miniprofiler has) at top of the page or add key listener(s). When triggered it would show database info. For example you are working on UsersController and when you press Cmd+D users table info slides down.
43 | - [ ] Generator to copy assets in case asset pipeline is disabled
44 |
45 | Contributions welcome :)
46 |
47 | ## Contributing
48 |
49 | 1. Fork it
50 | 2. Create your feature branch (git checkout -b my-new-feature)
51 | 3. Commit your changes (git commit -am 'Added some feature')
52 | 4. Push to the branch (git push origin my-new-feature)
53 | 5. Create new Pull Request
54 |
55 | ## Running tests
56 |
57 | ```
58 | $ RAILS_ENV=test bundle exec rake db:migrate
59 | $ bundle exec rake
60 | ```
61 |
62 | To run tests for specific rails version use custom Gemfile from [gemfiles](https://github.com/vlado/rails_db_info/tree/master/gemfiles) folder
63 |
64 | ```
65 | $ BUNDLE_GEMFILE=gemfiles/rails_3-2-stable.gemfile bundle install
66 | $ BUNDLE_GEMFILE=gemfiles/rails_3-2-stable.gemfile bundle exec rake
67 | ```
68 |
69 | ## License
70 |
71 | This project rocks and uses MIT-LICENSE.
72 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | begin
2 | require 'bundler/setup'
3 | rescue LoadError
4 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5 | end
6 |
7 | require 'rdoc/task'
8 |
9 | RDoc::Task.new(:rdoc) do |rdoc|
10 | rdoc.rdoc_dir = 'rdoc'
11 | rdoc.title = 'RailsDbInfo'
12 | rdoc.options << '--line-numbers'
13 | rdoc.rdoc_files.include('README.rdoc')
14 | rdoc.rdoc_files.include('lib/**/*.rb')
15 | end
16 |
17 | APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18 | load 'rails/tasks/engine.rake'
19 |
20 |
21 |
22 | Bundler::GemHelper.install_tasks
23 |
24 | require 'rake/testtask'
25 |
26 | Rake::TestTask.new(:test) do |t|
27 | t.libs << 'lib'
28 | t.libs << 'test'
29 | t.pattern = 'test/**/*_test.rb'
30 | t.verbose = false
31 | end
32 |
33 | task :default => :test
34 |
--------------------------------------------------------------------------------
/app/assets/images/rails_db_info/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/app/assets/images/rails_db_info/.keep
--------------------------------------------------------------------------------
/app/assets/javascripts/rails_db_info/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require_tree .
14 |
--------------------------------------------------------------------------------
/app/assets/javascripts/rails_db_info/tables.js:
--------------------------------------------------------------------------------
1 | // Place all the behaviors and hooks related to the matching controller here.
2 | // All this logic will automatically be available in application.js.
3 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/rails_db_info/application.css:
--------------------------------------------------------------------------------
1 | body { background-color: #fff; color: #333; }
2 |
3 | body, p, ol, ul, td {
4 | font-family: helvetica, verdana, arial, sans-serif;
5 | font-size: 13px;
6 | line-height: 18px;
7 | }
8 |
9 | a { color: #000; }
10 | a:visited { color: #666; }
11 | a:hover { color: #fff; background-color:#000; }
12 |
13 | h1 { padding-left: 10px; }
14 |
15 | table {
16 | border: 1px solid #999;
17 | border-spacing: 0;
18 | border-collapse: collapse;
19 | }
20 | table th {
21 | border-bottom: 1px solid #999;
22 | border: 1px solid #999;
23 | }
24 | table tbody tr:nth-child(even) {
25 | background: #EEE
26 | }
27 | table tbody tr:nth-child(odd) {
28 | background: #FFF
29 | }
30 | table tbody tr:hover {
31 | background-color: #333;
32 | color: #FFF;
33 | }
34 | table td {
35 | padding: 3px 10px;
36 | }
37 | table td {
38 | border-left: 1px solid #DDD;
39 | }
40 |
41 | ul.table-menu {
42 | list-style:none;
43 | margin:0;
44 | padding:0 0 10px 0;
45 | }
46 | ul.table-menu li {
47 | display:inline;
48 | padding:0 10px;
49 | }
50 |
51 | .pagination {
52 | margin:10px;
53 | }
54 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/rails_db_info/tables.css:
--------------------------------------------------------------------------------
1 | /*
2 | Place all the styles related to the matching controller here.
3 | They will automatically be included in application.css.
4 | */
5 |
--------------------------------------------------------------------------------
/app/controllers/rails_db_info/application_controller.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | class ApplicationController < ActionController::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/controllers/rails_db_info/tables_controller.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | class TablesController < RailsDbInfo::ApplicationController
3 |
4 | def index
5 | @tables = ActiveRecord::Base.connection.tables.sort
6 | end
7 |
8 | def show
9 | @table = RailsDbInfo::Table.new(params[:id])
10 | end
11 |
12 | def entries
13 | @table = RailsDbInfo::Table.new(params[:table_id])
14 | @entries = RailsDbInfo::TableEntries.new(@table).paginate(:page => params[:page])
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/app/helpers/rails_db_info/application_helper.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | module ApplicationHelper
3 |
4 | def paginate_table_entries(entries)
5 | return if entries.total_pages == 1
6 | prev_page_text = '< Previous'
7 | next_page_text = 'Next>'
8 |
9 | html = '
'
14 |
15 | sanitize(html)
16 | end
17 |
18 | private
19 |
20 | def page_links_for_pagination(entries)
21 | pages = pages_for_pagination(entries)
22 | links = []
23 |
24 | pages.each_with_index do |page,index|
25 | if page == entries.current_page
26 | links << content_tag(:b, page)
27 | else
28 | links << link_to(page, :page => page)
29 | end
30 | links << " ... " if page != pages.last && (page + 1) != pages[index+1]
31 | end
32 |
33 | links.join(' ')
34 | end
35 |
36 | def pages_for_pagination(entries)
37 | last_page = entries.total_pages
38 | current_page = entries.current_page
39 |
40 | pages = if last_page > 10
41 | [1, 2, 3] +
42 | (current_page-2..current_page+2).to_a +
43 | (last_page-2..last_page).to_a
44 | else
45 | (1..last_page).to_a
46 | end
47 |
48 | pages.uniq.select { |p| p > 0 && p <= last_page }
49 | end
50 |
51 | end
52 | end
53 |
--------------------------------------------------------------------------------
/app/helpers/rails_db_info/tables_helper.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | module TablesHelper
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/views/layouts/rails_db_info/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Database Info
5 | <%= stylesheet_link_tag "rails_db_info/application", :media => "all" %>
6 | <%# javascript_include_tag "rails_db_info/application" %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= render 'rails_db_info/tables/header' %>
12 |
13 | <%= yield %>
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/views/rails_db_info/tables/_header.html.erb:
--------------------------------------------------------------------------------
1 |
2 | <%= link_to "Tables", tables_path %>
3 | <% if @table %>
4 | | <%= @table.name %>
5 | <% end %>
6 |
7 |
8 | <% if @table %>
9 |
14 | <% end %>
15 |
--------------------------------------------------------------------------------
/app/views/rails_db_info/tables/entries.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <% @table.columns.each do |column| %>
5 | <%= column.name %> |
6 | <% end %>
7 |
8 |
9 |
10 | <% @entries.each do |record| %>
11 |
12 | <% @table.columns.map(&:name).each do |key| %>
13 | <%= record[key] %> |
14 | <% end %>
15 |
16 | <% end %>
17 |
18 |
19 |
20 | <%= paginate_table_entries @entries %>
21 |
--------------------------------------------------------------------------------
/app/views/rails_db_info/tables/index.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Table name |
5 | |
6 |
7 |
8 |
9 | <% @tables.each do |table| %>
10 |
11 | <%= table %> |
12 | <%= link_to 'Schema', table_path(table) %> |
13 | <%= link_to 'Entries', table_entries_path(table) %> |
14 |
15 | <% end -%>
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/views/rails_db_info/tables/show.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <% @table.column_properties.each do |key| %>
5 | <%= key %> |
6 | <% end %>
7 |
8 |
9 |
10 | <% @table.columns.each do |col| %>
11 |
12 | <% @table.column_properties.each do |key| %>
13 | <%= col.send(key) %> |
14 | <% end %>
15 |
16 | <% end %>
17 |
18 |
19 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3 |
4 | ENGINE_ROOT = File.expand_path('../..', __FILE__)
5 | ENGINE_PATH = File.expand_path('../../lib/rails_db_info/engine', __FILE__)
6 |
7 | require 'rails/all'
8 | require 'rails/engine/commands'
9 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | RailsDbInfo::Engine.routes.draw do
2 | root :to => 'tables#index'
3 | resources :tables, :only => [:index, :show] do
4 | get 'entries'
5 | end
6 | end
7 |
8 | Rails.application.routes.draw do
9 | mount_rails_db_info
10 | end
11 |
--------------------------------------------------------------------------------
/gemfiles/rails_3-1-stable.gemfile:
--------------------------------------------------------------------------------
1 | eval Pathname.new(__FILE__).join("../../Gemfile").read
2 |
3 | gem "rails", github: "rails/rails", branch: "3-1-stable"
4 | gem "test-unit"
5 |
6 |
--------------------------------------------------------------------------------
/gemfiles/rails_3-2-stable.gemfile:
--------------------------------------------------------------------------------
1 | eval Pathname.new(__FILE__).join("../../Gemfile").read
2 |
3 | gem "rails", github: "rails/rails", branch: "3-2-stable"
4 | gem "test-unit"
5 |
6 |
--------------------------------------------------------------------------------
/gemfiles/rails_4-0-stable.gemfile:
--------------------------------------------------------------------------------
1 | eval Pathname.new(__FILE__).join("../../Gemfile").read
2 |
3 | gem "rails", github: "rails/rails", branch: "4-0-stable"
4 |
5 |
--------------------------------------------------------------------------------
/gemfiles/rails_4-1-stable.gemfile:
--------------------------------------------------------------------------------
1 | eval Pathname.new(__FILE__).join("../../Gemfile").read
2 |
3 | gem "rails", github: "rails/rails", branch: "4-1-stable"
4 |
5 |
--------------------------------------------------------------------------------
/gemfiles/rails_4-2-stable.gemfile:
--------------------------------------------------------------------------------
1 | eval Pathname.new(__FILE__).join("../../Gemfile").read
2 |
3 | gem "rails", github: "rails/rails", branch: "4-2-stable"
4 |
5 |
--------------------------------------------------------------------------------
/gemfiles/ruby-1.8.7.gemfile:
--------------------------------------------------------------------------------
1 | eval Pathname.new(__FILE__).join("../../Gemfile").read
2 |
3 | gem "rails", :github => "rails/rails", :branch => "3-2-stable"
4 | gem "i18n", "0.6.9"
5 | gem "pg", "0.17.0"
6 |
7 |
--------------------------------------------------------------------------------
/lib/rails/routes.rb:
--------------------------------------------------------------------------------
1 | module ActionDispatch::Routing
2 | class Mapper
3 | # Includes mount_rails_db_info method for routes. This method is responsible to
4 | # generate all needed routes for rails_db_info
5 | def mount_rails_db_info(options = {})
6 | mount RailsDbInfo::Engine => "/rails/info/db", :as => options[:as] || 'rails_db_info'
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/lib/rails_db_info.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | # Custom require relative that work with older rubies also
3 | def self.require_relative(path)
4 | full_path = File.expand_path(path, File.dirname(__FILE__))
5 | Kernel.require(full_path)
6 | end
7 | end
8 |
9 | require "rails_db_info/engine"
10 | RailsDbInfo.require_relative("rails/routes")
11 |
12 |
--------------------------------------------------------------------------------
/lib/rails_db_info/engine.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | class Engine < ::Rails::Engine
3 | isolate_namespace RailsDbInfo
4 | config.autoload_paths += Dir["#{config.root}/lib"]
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/lib/rails_db_info/table.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | class Table
3 |
4 | attr_reader :name
5 |
6 | def initialize(table_name)
7 | @name = table_name
8 | end
9 |
10 | def columns
11 | connection.columns(name)
12 | end
13 |
14 | def column_properties
15 | %w(name sql_type null limit precision scale type default)
16 | end
17 |
18 | def to_param
19 | name
20 | end
21 |
22 |
23 | private
24 |
25 | def connection
26 | ActiveRecord::Base.connection
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/lib/rails_db_info/table_entries.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | class TableEntries
3 |
4 | attr_reader :table
5 | attr_accessor :current_page, :offset, :per_page
6 |
7 | delegate :each, :to => :load
8 |
9 | def initialize(table)
10 | @table = table
11 | end
12 |
13 | def load
14 | connection.exec_query("SELECT * FROM #{table.name} LIMIT #{per_page} OFFSET #{offset}")
15 | end
16 |
17 | def next_page
18 | current_page < total_pages ? (current_page + 1) : nil
19 | end
20 |
21 | def paginate(options = {})
22 | self.per_page = 10
23 | self.current_page = (options[:page] || 1).to_i
24 | self.offset = current_page * per_page - per_page
25 | self
26 | end
27 |
28 | def previous_page
29 | current_page > 1 ? (current_page - 1) : nil
30 | end
31 |
32 | def total_entries
33 | @total_entries ||= count
34 | end
35 |
36 | def total_pages
37 | total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil
38 | end
39 |
40 |
41 | private
42 |
43 | def count
44 | connection.exec_query("SELECT COUNT(*) FROM #{table.name}").rows.flatten.last.to_i
45 | end
46 |
47 | def connection
48 | ActiveRecord::Base.connection
49 | end
50 |
51 | end
52 | end
53 |
--------------------------------------------------------------------------------
/lib/rails_db_info/version.rb:
--------------------------------------------------------------------------------
1 | module RailsDbInfo
2 | VERSION = "0.2.0"
3 | end
4 |
--------------------------------------------------------------------------------
/lib/tasks/rails_db_info_tasks.rake:
--------------------------------------------------------------------------------
1 | # desc "Explaining what the task does"
2 | # task :rails_db_info do
3 | # # Task goes here
4 | # end
5 |
--------------------------------------------------------------------------------
/rails_db_info.gemspec:
--------------------------------------------------------------------------------
1 | $:.push File.expand_path("../lib", __FILE__)
2 |
3 | # Maintain your gem's version:
4 | require "rails_db_info/version"
5 |
6 | # Describe your gem and declare its dependencies:
7 | Gem::Specification.new do |s|
8 | s.name = "rails_db_info"
9 | s.version = RailsDbInfo::VERSION
10 | s.authors = ["Vlado Cingel"]
11 | s.email = ["vladocingel@gmail.com"]
12 | s.homepage = "https://github.com/vlado/rails_db_info"
13 | s.summary = "RailsDbInfo is a Rails engine that quickly shows the database info"
14 | s.description = "RailsDbInfo is a Rails engine that quickly shows the database info"
15 | s.license = "MIT"
16 |
17 | s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
18 | s.test_files = Dir["test/**/*"]
19 |
20 | s.add_dependency "rails", ">= 3.1.0"
21 |
22 | s.add_development_dependency "mysql2"
23 | s.add_development_dependency "pg"
24 | s.add_development_dependency "sqlite3", ">= 1.3.10"
25 | end
26 |
--------------------------------------------------------------------------------
/test/controllers/rails_db_info/tables_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | module RailsDbInfo
4 | class TablesControllerTest < ActionController::TestCase
5 | # test "the truth" do
6 | # assert true
7 | # end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/test/dummy/README.rdoc:
--------------------------------------------------------------------------------
1 | == README
2 |
3 | This README would normally document whatever steps are necessary to get the
4 | application up and running.
5 |
6 | Things you may want to cover:
7 |
8 | * Ruby version
9 |
10 | * System dependencies
11 |
12 | * Configuration
13 |
14 | * Database creation
15 |
16 | * Database initialization
17 |
18 | * How to run the test suite
19 |
20 | * Services (job queues, cache servers, search engines, etc.)
21 |
22 | * Deployment instructions
23 |
24 | * ...
25 |
26 |
27 | Please feel free to use a different markup language if you do not plan to run
28 | rake doc:app.
29 |
--------------------------------------------------------------------------------
/test/dummy/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Dummy::Application.load_tasks
7 |
--------------------------------------------------------------------------------
/test/dummy/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/app/assets/images/.keep
--------------------------------------------------------------------------------
/test/dummy/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require_tree .
14 |
--------------------------------------------------------------------------------
/test/dummy/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the top of the
9 | * compiled file, but it's generally better to create a new file per style scope.
10 | *
11 | *= require_self
12 | *= require_tree .
13 | */
14 |
--------------------------------------------------------------------------------
/test/dummy/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery :with => :exception
5 | end
6 |
--------------------------------------------------------------------------------
/test/dummy/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/test/dummy/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/test/dummy/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/app/mailers/.keep
--------------------------------------------------------------------------------
/test/dummy/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/app/models/.keep
--------------------------------------------------------------------------------
/test/dummy/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/app/models/concerns/.keep
--------------------------------------------------------------------------------
/test/dummy/app/models/user.rb:
--------------------------------------------------------------------------------
1 | class User < ActiveRecord::Base
2 | end
3 |
--------------------------------------------------------------------------------
/test/dummy/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dummy
5 | <%= stylesheet_link_tag "application", :media => "all", "data-turbolinks-track" => true %>
6 | <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/dummy/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/test/dummy/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_PATH = File.expand_path('../../config/application', __FILE__)
3 | require_relative '../config/boot'
4 | require 'rails/commands'
5 |
--------------------------------------------------------------------------------
/test/dummy/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require_relative '../config/boot'
3 | require 'rake'
4 | Rake.application.run
5 |
--------------------------------------------------------------------------------
/test/dummy/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/test/dummy/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | Bundler.require(*Rails.groups)
6 | require "rails_db_info"
7 |
8 | module Dummy
9 | class Application < Rails::Application
10 | # Settings in config/environments/* take precedence over those specified here.
11 | # Application configuration should go into files in config/initializers
12 | # -- all .rb files in that directory are automatically loaded.
13 |
14 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16 | # config.time_zone = 'Central Time (US & Canada)'
17 |
18 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20 | # config.i18n.default_locale = :de
21 | end
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/test/dummy/config/boot.rb:
--------------------------------------------------------------------------------
1 | # Set up gems listed in the Gemfile.
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3 |
4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
6 |
--------------------------------------------------------------------------------
/test/dummy/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | development:
7 | adapter: sqlite3
8 | database: db/development.sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | # Warning: The database defined as "test" will be erased and
13 | # re-generated from your development database when you run "rake".
14 | # Do not set this db to the same as development or production.
15 |
16 | test_sqlite: &sqlite
17 | adapter: sqlite3
18 | database: db/test.sqlite3
19 |
20 | test_myqsl: &mysql
21 | adapter: mysql2
22 | database: rails_db_info_test
23 | username: travis
24 | encoding: utf8
25 |
26 | test_postgresql: &postgresql
27 | adapter: postgresql
28 | database: rails_db_info_test
29 | username: postgres
30 |
31 | test:
32 | pool: 5
33 | timeout: 5000
34 | <<: *<%= ENV['DB'] || 'sqlite' %>
35 |
36 | production:
37 | adapter: sqlite3
38 | database: db/production.sqlite3
39 | pool: 5
40 | timeout: 5000
41 |
--------------------------------------------------------------------------------
/test/dummy/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Dummy::Application.initialize!
6 |
--------------------------------------------------------------------------------
/test/dummy/config/environments/development.rb:
--------------------------------------------------------------------------------
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 | # Do not eager load code on boot.
10 | config.eager_load = false
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 | # Raise an error on page load if there are pending migrations
23 | config.active_record.migration_error = :page_load
24 |
25 | # Debug mode disables concatenation and preprocessing of assets.
26 | # This option may cause significant delays in view rendering with a large
27 | # number of complex assets.
28 | config.assets.debug = true
29 | end
30 |
--------------------------------------------------------------------------------
/test/dummy/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both thread web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
18 | # Add `rack-cache` to your Gemfile before enabling this.
19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20 | # config.action_dispatch.rack_cache = true
21 |
22 | # Disable Rails's static asset server (Apache or nginx will already do this).
23 | config.serve_static_files = false
24 |
25 | # Compress JavaScripts and CSS.
26 | config.assets.js_compressor = :uglifier
27 | # config.assets.css_compressor = :sass
28 |
29 | # Do not fallback to assets pipeline if a precompiled asset is missed.
30 | config.assets.compile = false
31 |
32 | # Generate digests for assets URLs.
33 | config.assets.digest = true
34 |
35 | # Version of your assets, change this if you want to expire all your assets.
36 | config.assets.version = '1.0'
37 |
38 | # Specifies the header that your server uses for sending files.
39 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
40 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41 |
42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43 | # config.force_ssl = true
44 |
45 | # Set to :debug to see everything in the log.
46 | config.log_level = :info
47 |
48 | # Prepend all log lines with the following tags.
49 | # config.log_tags = [ :subdomain, :uuid ]
50 |
51 | # Use a different logger for distributed setups.
52 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53 |
54 | # Use a different cache store in production.
55 | # config.cache_store = :mem_cache_store
56 |
57 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
58 | # config.action_controller.asset_host = "http://assets.example.com"
59 |
60 | # Precompile additional assets.
61 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
62 | # config.assets.precompile += %w( search.js )
63 |
64 | # Ignore bad email addresses and do not raise email delivery errors.
65 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
66 | # config.action_mailer.raise_delivery_errors = false
67 |
68 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
69 | # the I18n.default_locale when a translation can not be found).
70 | config.i18n.fallbacks = true
71 |
72 | # Send deprecation notices to registered listeners.
73 | config.active_support.deprecation = :notify
74 |
75 | # Disable automatic flushing of the log to improve performance.
76 | # config.autoflush_log = false
77 |
78 | # Use default logging formatter so that PID and timestamp are not suppressed.
79 | config.log_formatter = ::Logger::Formatter.new
80 | end
81 |
--------------------------------------------------------------------------------
/test/dummy/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure static asset server for tests with Cache-Control for performance.
16 | config.serve_static_files = true
17 | config.static_cache_control = "public, max-age=3600"
18 |
19 | # Show full error reports and disable caching.
20 | config.consider_all_requests_local = true
21 | config.action_controller.perform_caching = false
22 |
23 | # Raise exceptions instead of rendering exception templates.
24 | config.action_dispatch.show_exceptions = false
25 |
26 | # Disable request forgery protection in test environment.
27 | config.action_controller.allow_forgery_protection = false
28 |
29 | # Tell Action Mailer not to deliver emails to the real world.
30 | # The :test delivery method accumulates sent emails in the
31 | # ActionMailer::Base.deliveries array.
32 | config.action_mailer.delivery_method = :test
33 |
34 | # Print deprecation notices to the stderr.
35 | config.active_support.deprecation = :stderr
36 |
37 | config.active_support.test_order = :random
38 | end
39 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
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!
8 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure your secret_key_base is kept private
11 | # if you're sharing your code publicly.
12 | Dummy::Application.config.secret_key_base = '1a1ee498b732b31d74126d94454b3f5080d3ec869086da6c2d165e3bb02b77e8fc3cf16aa86651fe3fcebeba0e6270aa6ebf1baa41300c93b8074e6e25d8ec1c'
13 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Dummy::Application.config.secret_token = "some secret phrase of at least 30 characters"
4 | Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
5 |
--------------------------------------------------------------------------------
/test/dummy/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
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 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters :format => [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/test/dummy/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/test/dummy/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | if ENV['CATCH_ALL_ROUTE']
3 | mount_rails_db_info :as => 'rails_db_info_engine'
4 | get '*path' => 'foo#bar'
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/test/dummy/db/migrate/20130819203338_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration
2 | def change
3 | create_table :users do |t|
4 | t.string :username
5 | t.string :email
6 | t.integer :age
7 | t.boolean :admin
8 |
9 | t.timestamps
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/test/dummy/db/schema.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # This file is auto-generated from the current state of the database. Instead
3 | # of editing this file, please use the migrations feature of Active Record to
4 | # incrementally modify your database, and then regenerate this schema definition.
5 | #
6 | # Note that this schema.rb definition is the authoritative source for your
7 | # database schema. If you need to create the application database on another
8 | # system, you should be using db:schema:load, not running all the migrations
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 | # you'll amass, the slower it'll run and the greater likelihood for issues).
11 | #
12 | # It's strongly recommended that you check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(version: 20130819203338) do
15 |
16 | create_table "users", force: :cascade do |t|
17 | t.string "username"
18 | t.string "email"
19 | t.integer "age"
20 | t.boolean "admin"
21 | t.datetime "created_at"
22 | t.datetime "updated_at"
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/test/dummy/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/lib/assets/.keep
--------------------------------------------------------------------------------
/test/dummy/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/log/.keep
--------------------------------------------------------------------------------
/test/dummy/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
48 |
49 |
50 |
51 |
52 |
53 |
The page you were looking for doesn't exist.
54 |
You may have mistyped the address or the page may have moved.
55 |
56 | If you are the application owner check the logs for more information.
57 |
58 |
59 |
--------------------------------------------------------------------------------
/test/dummy/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
48 |
49 |
50 |
51 |
52 |
53 |
The change you wanted was rejected.
54 |
Maybe you tried to change something you didn't have access to.
55 |
56 | If you are the application owner check the logs for more information.
57 |
58 |
59 |
--------------------------------------------------------------------------------
/test/dummy/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
48 |
49 |
50 |
51 |
52 |
53 |
We're sorry, but something went wrong.
54 |
55 | If you are the application owner check the logs for more information.
56 |
57 |
58 |
--------------------------------------------------------------------------------
/test/dummy/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vlado/rails_db_info/910f09345c92248a19d7b0dfffec75ce247cf62c/test/dummy/public/favicon.ico
--------------------------------------------------------------------------------
/test/dummy/test/fixtures/users.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2 |
3 | one:
4 | username: MyString
5 | email: MyString
6 | age: 1
7 | admin: false
8 |
9 | two:
10 | username: MyString
11 | email: MyString
12 | age: 1
13 | admin: false
14 |
--------------------------------------------------------------------------------
/test/dummy/test/models/user_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UserTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/helpers/rails_db_info/tables_helper_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | module RailsDbInfo
4 | class TablesHelperTest < ActionView::TestCase
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/test/integration/catch_all_routes_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class CatchAllRoutesTest < ActionDispatch::IntegrationTest
4 | setup do
5 | ENV['CATCH_ALL_ROUTE'] = 'catch'
6 | Rails.application.reload_routes!
7 | end
8 |
9 | teardown do
10 | ENV.delete('CATCH_ALL_ROUTE')
11 | Rails.application.reload_routes!
12 | end
13 |
14 | test "I see list of tables when I visit rails_db_info dashboard" do
15 | get '/rails/info/db'
16 |
17 | assert assigns(:tables)
18 | assert_select 'h1', 'Tables'
19 | %w(schema_migrations users).each do |table|
20 | assert_select 'table.tables tr td', table
21 | end
22 | end
23 |
24 | test 'I see table column details when I visit table page' do
25 | get '/rails/info/db/tables/users'
26 |
27 | assert assigns(:table)
28 | assert_select 'h1', /users/
29 | User.columns.each do |col|
30 | assert_select "table tr td.name", col.name
31 | assert_select "table tr td.sql_type", col.sql_type
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/test/integration/navigation_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class NavigationTest < ActionDispatch::IntegrationTest
4 | # fixtures :all
5 |
6 | test "I see list of tables when I visit rails_db_info dashboard" do
7 | get '/rails/info/db'
8 |
9 | assert assigns(:tables)
10 | assert_select 'h1', 'Tables'
11 | %w(schema_migrations users).each do |table|
12 | assert_select 'table.tables tr td', table
13 | end
14 | end
15 |
16 | test 'I see table column details when I visit table page' do
17 | get '/rails/info/db/tables/users'
18 |
19 | assert assigns(:table)
20 | assert_select 'h1', /users/
21 | User.columns.each do |col|
22 | assert_select "table tr td.name", col.name
23 | assert_select "table tr td.sql_type", col.sql_type
24 | end
25 | end
26 |
27 | test 'I see table title, column names and values when I visit show table entries page' do
28 | User.create([
29 | { :username => 'vlado', :email => 'vlado@cingel.hr', :age => 33, :admin => true },
30 | { :username => 'ana', :email => 'ana@cingel.hr', :age => 34, :admin => false }
31 | ])
32 |
33 | get '/rails/info/db/tables/users/entries'
34 |
35 | assert assigns(:table)
36 | assert_select 'h1', /users/
37 | User.column_names.each do |col|
38 | assert_select 'table thead tr:first-child th', col
39 | end
40 | assert_equal 2, css_select('table tbody tr').size
41 | assert_select 'table tbody tr:first-child td.username', 'vlado'
42 | assert_select 'table tbody tr:last-child td.username', 'ana'
43 | end
44 |
45 | test 'I can paginate through entires' do
46 | 25.times do |i|
47 | User.create(:username => "vlado#{i+1}", :email => "vlado#{i+1}@cingel.hr", :age => 33, :admin => true)
48 | end
49 |
50 | get '/rails/info/db/tables/users/entries'
51 | assert_equal 10, css_select('table tbody tr').size
52 | assert_select 'table tbody tr:first-child td.username', 'vlado1'
53 | assert_select 'table tbody tr:last-child td.username', 'vlado10'
54 |
55 | get '/rails/info/db/tables/users/entries?page=1'
56 | assert_equal 10, css_select('table tbody tr').size
57 | assert_select 'table tbody tr:first-child td.username', 'vlado1'
58 | assert_select 'table tbody tr:last-child td.username', 'vlado10'
59 |
60 | get '/rails/info/db/tables/users/entries?page=2'
61 | assert_equal 10, css_select('table tbody tr').size
62 | assert_select 'table tbody tr:first-child td.username', 'vlado11'
63 | assert_select 'table tbody tr:last-child td.username', 'vlado20'
64 |
65 | get '/rails/info/db/tables/users/entries?page=3'
66 | assert_equal 5, css_select('table tbody tr').size
67 | assert_select 'table tbody tr:first-child td.username', 'vlado21'
68 | assert_select 'table tbody tr:last-child td.username', 'vlado25'
69 | end
70 | end
71 |
72 |
--------------------------------------------------------------------------------
/test/rails_db_info_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class RailsDbInfoTest < ActiveSupport::TestCase
4 | test "truth" do
5 | assert_kind_of Module, RailsDbInfo
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | # Configure Rails Environment
2 | ENV["RAILS_ENV"] = "test"
3 |
4 | require File.expand_path("../dummy/config/environment.rb", __FILE__)
5 | require "rails/test_help"
6 |
7 | Rails.backtrace_cleaner.remove_silencers!
8 |
9 | # Load support files
10 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11 |
12 | # Load fixtures from the engine
13 | if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14 | ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15 | end
16 |
--------------------------------------------------------------------------------