dbhero 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +21 -0
  4. data/app/assets/javascripts/dbhero/application.js +45 -0
  5. data/app/assets/javascripts/dbhero/dataclips.js +42 -0
  6. data/app/assets/stylesheets/dbhero/application.css.scss +88 -0
  7. data/app/controllers/dbhero/application_controller.rb +30 -0
  8. data/app/controllers/dbhero/dataclips_controller.rb +84 -0
  9. data/app/helpers/dbhero/application_helper.rb +4 -0
  10. data/app/helpers/dbhero/dataclips_helper.rb +4 -0
  11. data/app/models/dbhero/dataclip.rb +50 -0
  12. data/app/views/dbhero/dataclips/_clip_table.html.slim +38 -0
  13. data/app/views/dbhero/dataclips/_form.html.slim +32 -0
  14. data/app/views/dbhero/dataclips/edit.html.slim +6 -0
  15. data/app/views/dbhero/dataclips/index.html.slim +25 -0
  16. data/app/views/dbhero/dataclips/new.html.slim +2 -0
  17. data/app/views/dbhero/dataclips/show.html.slim +18 -0
  18. data/app/views/layouts/dbhero/application.html.slim +24 -0
  19. data/config/routes.rb +6 -0
  20. data/lib/dbhero.rb +7 -0
  21. data/lib/dbhero/configuration.rb +39 -0
  22. data/lib/dbhero/engine.rb +9 -0
  23. data/lib/dbhero/gdrive_exporter.rb +56 -0
  24. data/lib/dbhero/router_constraint.rb +43 -0
  25. data/lib/dbhero/version.rb +3 -0
  26. data/lib/generators/dbhero/install/install_generator.rb +29 -0
  27. data/lib/generators/dbhero/install/templates/dbhero.rb +26 -0
  28. data/lib/generators/dbhero/install/templates/migrations/create_dbhero_dataclips.rb +17 -0
  29. data/lib/tasks/dbhero_tasks.rake +4 -0
  30. data/spec/controllers/dbhero/dataclips_controller_spec.rb +293 -0
  31. data/spec/dummy/README.rdoc +28 -0
  32. data/spec/dummy/Rakefile +6 -0
  33. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  34. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  35. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  37. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  38. data/spec/dummy/bin/bundle +3 -0
  39. data/spec/dummy/bin/rails +4 -0
  40. data/spec/dummy/bin/rake +4 -0
  41. data/spec/dummy/config.ru +4 -0
  42. data/spec/dummy/config/application.rb +27 -0
  43. data/spec/dummy/config/boot.rb +5 -0
  44. data/spec/dummy/config/database.yml +85 -0
  45. data/spec/dummy/config/environment.rb +5 -0
  46. data/spec/dummy/config/environments/development.rb +37 -0
  47. data/spec/dummy/config/environments/production.rb +78 -0
  48. data/spec/dummy/config/environments/test.rb +39 -0
  49. data/spec/dummy/config/initializers/assets.rb +8 -0
  50. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  52. data/spec/dummy/config/initializers/dbhero.rb +26 -0
  53. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  54. data/spec/dummy/config/initializers/inflections.rb +16 -0
  55. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  56. data/spec/dummy/config/initializers/session_store.rb +3 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +23 -0
  59. data/spec/dummy/config/routes.rb +4 -0
  60. data/spec/dummy/config/secrets.yml +22 -0
  61. data/spec/dummy/db/migrate/20150323172444_create_dbhero_dataclips.rb +17 -0
  62. data/spec/dummy/db/schema.rb +32 -0
  63. data/spec/dummy/log/development.log +27 -0
  64. data/spec/dummy/log/test.log +3758 -0
  65. data/spec/dummy/public/404.html +67 -0
  66. data/spec/dummy/public/422.html +67 -0
  67. data/spec/dummy/public/500.html +66 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/factories.rb +8 -0
  70. data/spec/models/dbhero/dataclip_spec.rb +119 -0
  71. data/spec/rails_helper.rb +57 -0
  72. data/spec/spec_helper.rb +90 -0
  73. metadata +312 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
data/spec/factories.rb ADDED
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+ factory :dataclip, class: Dbhero::Dataclip do
3
+ description "Dummy query\nwich describes a dummy string and database version"
4
+ raw_query "select 'dummy_foo' as dummy_bar, vesion() as db_version"
5
+ private false
6
+ end
7
+ end
8
+
@@ -0,0 +1,119 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Dbhero::Dataclip, type: :model do
4
+ context "Validations" do
5
+ it{ is_expected.to validate_presence_of(:description) }
6
+ it{ is_expected.to validate_presence_of(:raw_query) }
7
+ end
8
+
9
+ context "before create" do
10
+ describe ".set_token" do
11
+ subject { build(:dataclip) }
12
+
13
+ it "token should be nil when clip is not persisted" do
14
+ expect(subject.token).to be_nil
15
+ end
16
+
17
+ it "token should be present after create clip" do
18
+ subject.save
19
+ expect(subject.token).not_to be_nil
20
+ end
21
+ end
22
+ end
23
+
24
+ context ".ordered" do
25
+ before do
26
+ @clip_01 = create(:dataclip, updated_at: 2.days.ago )
27
+ @clip_02 = create(:dataclip, updated_at: 1.days.ago )
28
+ @clip_03 = create(:dataclip, updated_at: 4.days.ago )
29
+ end
30
+
31
+ subject { Dbhero::Dataclip.ordered }
32
+
33
+ it do
34
+ is_expected.to eq([@clip_02, @clip_01, @clip_03])
35
+ end
36
+ end
37
+
38
+ context "#to_param" do
39
+ let(:dataclip) { create(:dataclip) }
40
+ subject { dataclip.to_param }
41
+
42
+ it { is_expected.to eq(dataclip.token) }
43
+ end
44
+
45
+ context "#title" do
46
+ let(:dataclip) { create(:dataclip, description: "title\ndescription\nfoo") }
47
+ subject { dataclip.title }
48
+
49
+ it { is_expected.to eq("title") }
50
+ end
51
+
52
+ context "#description_without_title" do
53
+ let(:dataclip) { create(:dataclip, description: "title\ndescription\nfoo") }
54
+ subject { dataclip.description_without_title }
55
+
56
+ it { is_expected.to eq("description\nfoo") }
57
+ end
58
+
59
+ context "#csv_string" do
60
+ let(:dataclip) { create(:dataclip, raw_query: "select 'foo'::text as bar, 'bar'::text as foo") }
61
+ subject { dataclip.csv_string }
62
+
63
+ it { is_expected.to eq("bar,foo\nfoo,bar\n")}
64
+ end
65
+
66
+ context "#total_rows" do
67
+ let(:dataclip) { create(:dataclip, raw_query: "select foo.nest from (select unnest(ARRAY[1,2,3]) as nest) foo") }
68
+ before { dataclip.query_result }
69
+ subject { dataclip.total_rows }
70
+
71
+ it { is_expected.to eq(3) }
72
+ end
73
+
74
+ context "#query_result" do
75
+ context "executes raw_query and return they result on q_result" do
76
+ let(:dataclip) { create(:dataclip, raw_query: "select 'foo'::text as bar, 'bar'::text as foo") }
77
+ before { dataclip.query_result }
78
+ subject { dataclip.q_result }
79
+
80
+ it "should be kind of ActiveRecord::Result" do
81
+ is_expected.to be_an_instance_of(ActiveRecord::Result)
82
+ end
83
+
84
+ it "explore on result set" do
85
+ expect(subject.columns).to eq(["bar", "foo"])
86
+ expect(subject.rows).to eq([["foo", "bar"]])
87
+ end
88
+ end
89
+
90
+ context "test some security" do
91
+ context "with truncate" do
92
+ let(:dataclip) { create(:dataclip, raw_query: "TRUNCATE table dbhero_dataclips") }
93
+
94
+ before do
95
+ 5.times { create(:dataclip) }
96
+ end
97
+
98
+ it "should not truncate table dataclips" do
99
+ dataclip.query_result
100
+ expect(Dbhero::Dataclip.count).to eq(6)
101
+ end
102
+ end
103
+
104
+ context "with commit" do
105
+ let(:dataclip) { create(:dataclip, raw_query: "TRUNCATE table dbhero_dataclips; commit;") }
106
+
107
+ before do
108
+ 5.times { create(:dataclip) }
109
+ end
110
+
111
+ it "should not truncate table dataclips" do
112
+ dataclip.query_result
113
+ expect(Dbhero::Dataclip.count).to eq(6)
114
+ expect(dataclip.errors.full_messages.to_sentence.match(/(PG\:\:SyntaxError\: ERROR)/)).not_to be_nil
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,57 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require 'spec_helper'
4
+ require File.expand_path("../dummy/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+ require 'factory_girl'
7
+ require 'factories'
8
+ require 'shoulda/matchers'
9
+ # Add additional requires below this line. Rails is not loaded until this point!
10
+
11
+ # Requires supporting ruby files with custom matchers and macros, etc, in
12
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
13
+ # run as spec files by default. This means that files in spec/support that end
14
+ # in _spec.rb will both be required and run as specs, causing the specs to be
15
+ # run twice. It is recommended that you do not name files matching this glob to
16
+ # end with _spec.rb. You can configure this pattern with the --pattern
17
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
18
+ #
19
+ # The following line is provided for convenience purposes. It has the downside
20
+ # of increasing the boot-up time by auto-requiring all files in the support
21
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
22
+ # require only the support files necessary.
23
+ #
24
+
25
+ # Checks for pending migrations before tests are run.
26
+ # If you are not using ActiveRecord, you can remove this line.
27
+ ActiveRecord::Migration.maintain_test_schema!
28
+
29
+ RSpec.configure do |config|
30
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
31
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
32
+ config.include FactoryGirl::Syntax::Methods
33
+
34
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
35
+ # examples within a transaction, remove the following line or assign false
36
+ # instead of true.
37
+ config.use_transactional_fixtures = true
38
+
39
+ # RSpec Rails can automatically mix in different behaviours to your tests
40
+ # based on their file location, for example enabling you to call `get` and
41
+ # `post` in specs under `spec/controllers`.
42
+ #
43
+ # You can disable this behaviour by removing the line below, and instead
44
+ # explicitly tag your specs with their type, e.g.:
45
+ #
46
+ # RSpec.describe UsersController, :type => :controller do
47
+ # # ...
48
+ # end
49
+ #
50
+ # The different available types are documented in the features, such as in
51
+ # https://relishapp.com/rspec/rspec-rails/docs
52
+ config.infer_spec_type_from_file_location!
53
+
54
+ config.expect_with :rspec do |c|
55
+ c.syntax = :expect
56
+ end
57
+ end
@@ -0,0 +1,90 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ =begin
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Limits the available syntax to the non-monkey patched syntax that is
57
+ # recommended. For more details, see:
58
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
61
+ config.disable_monkey_patching!
62
+
63
+ # Many RSpec users commonly either run the entire suite or an individual
64
+ # file, and it's useful to allow more verbose output when running an
65
+ # individual spec file.
66
+ if config.files_to_run.one?
67
+ # Use the documentation formatter for detailed output,
68
+ # unless a formatter has already been configured
69
+ # (e.g. via a command-line flag).
70
+ config.default_formatter = 'doc'
71
+ end
72
+
73
+ # Print the 10 slowest examples and example groups at the
74
+ # end of the spec run, to help surface which specs are running
75
+ # particularly slow.
76
+ config.profile_examples = 10
77
+
78
+ # Run specs in random order to surface order dependencies. If you find an
79
+ # order dependency and want to debug it, you can fix the order by providing
80
+ # the seed, which is printed after each run.
81
+ # --seed 1234
82
+ config.order = :random
83
+
84
+ # Seed global randomization in this process using the `--seed` CLI option.
85
+ # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # test failures related to randomization by passing the same `--seed` value
87
+ # as the one that triggered the failure.
88
+ Kernel.srand config.seed
89
+ =end
90
+ end