Skip to content

Commit

Permalink
Add a dummy app so we can do real queries in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeclaghorn committed May 12, 2020
1 parent 146c76c commit 3a74781
Show file tree
Hide file tree
Showing 82 changed files with 1,007 additions and 119 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -19,8 +19,11 @@ jobs:
key: ${{ runner.os }}-bundler-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: ${{ runner.os }}-bundler-

- name: Install dependencies
run: gem install bundler && bundle install --jobs 4 --retry 3 --path vendor/bundle
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install libsqlite3-dev

- name: Install gem dependencies
run: gem install bundler && bundle install --jobs 4 --retry 3 --path vendor/bundle

- name: Run tests
run: bundle exec rake test
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
.byebug_history

test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/node_modules/
test/dummy/yarn-error.log
test/dummy/storage/
test/dummy/tmp/
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -4,4 +4,6 @@ gemspec

gem 'rake'
gem 'byebug'
gem 'actionpack', '>= 5'

gem 'rails', '>= 5.0'
gem 'sqlite3'
124 changes: 103 additions & 21 deletions Gemfile.lock
Expand Up @@ -8,63 +8,145 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionpack (5.2.2)
actionview (= 5.2.2)
activesupport (= 5.2.2)
rack (~> 2.0)
actioncable (6.0.2.2)
actionpack (= 6.0.2.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.2.2)
actionpack (= 6.0.2.2)
activejob (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
mail (>= 2.7.1)
actionmailer (6.0.2.2)
actionpack (= 6.0.2.2)
actionview (= 6.0.2.2)
activejob (= 6.0.2.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.2.2)
actionview (= 6.0.2.2)
activesupport (= 6.0.2.2)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.2)
activesupport (= 5.2.2)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.2.2)
actionpack (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
nokogiri (>= 1.8.5)
actionview (6.0.2.2)
activesupport (= 6.0.2.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activesupport (5.2.2)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.2.2)
activesupport (= 6.0.2.2)
globalid (>= 0.3.6)
activemodel (6.0.2.2)
activesupport (= 6.0.2.2)
activerecord (6.0.2.2)
activemodel (= 6.0.2.2)
activesupport (= 6.0.2.2)
activestorage (6.0.2.2)
actionpack (= 6.0.2.2)
activejob (= 6.0.2.2)
activerecord (= 6.0.2.2)
marcel (~> 0.3.1)
activesupport (6.0.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
builder (3.2.3)
builder (3.2.4)
byebug (10.0.2)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.6)
crass (1.0.6)
erubi (1.7.1)
i18n (1.2.0)
erubi (1.9.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
loofah (2.4.0)
loofah (2.5.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (1.0.0)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
nokogiri (1.10.8)
minitest (5.14.0)
nio4r (2.5.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
public_suffix (3.0.3)
rack (2.2.2)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.2.2)
actioncable (= 6.0.2.2)
actionmailbox (= 6.0.2.2)
actionmailer (= 6.0.2.2)
actionpack (= 6.0.2.2)
actiontext (= 6.0.2.2)
actionview (= 6.0.2.2)
activejob (= 6.0.2.2)
activemodel (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
bundler (>= 1.3.0)
railties (= 6.0.2.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rake (12.3.3)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.0.2.2)
actionpack (= 6.0.2.2)
activesupport (= 6.0.2.2)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rake (12.3.2)
sprockets (4.0.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.5)
tzinfo (1.2.7)
thread_safe (~> 0.1)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
zeitwerk (2.3.0)

PLATFORMS
ruby

DEPENDENCIES
actionpack (>= 5)
bundler (~> 1.12)
byebug
geared_pagination!
rails (>= 5.0)
rake
sqlite3

BUNDLED WITH
1.17.2
16 changes: 16 additions & 0 deletions bin/rails
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/geared_pagination/engine', __dir__)
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails'
require 'action_controller/railtie'
require 'rails/test_unit/railtie'
require 'rails/engine/commands'
2 changes: 1 addition & 1 deletion lib/geared_pagination.rb
@@ -1,2 +1,2 @@
require 'geared_pagination/recordset'
require 'geared_pagination/railtie' if defined?(Rails)
require 'geared_pagination/engine' if defined?(Rails)
@@ -1,4 +1,4 @@
require 'rails/railtie'
require 'rails/engine'
require 'geared_pagination/controller'

class GearedPagination::Engine < ::Rails::Engine
Expand Down
26 changes: 2 additions & 24 deletions test/controller_test.rb
Expand Up @@ -4,32 +4,10 @@
require 'active_support/all'
require 'action_controller'

class RecordingsController < ActionController::Base
include GearedPagination::Controller

def index
set_page_and_extract_portion_from Recording.all, per_page: params[:per_page]
render json: @page.records if stale? etag: "placeholder"
end

def unpaged
@page = "not a geared pagination page"
head :ok if stale? etag: "placeholder"
end
end

class GearedPagination::ControllerTest < ActionController::TestCase
tests RecordingsController

setup do
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw do
resources :recordings do
get :unpaged, on: :collection
end
end
end
end
setup :create_recordings

test "ETag includes the current page and gearing" do
get :index, params: { per_page: [ 1, 2 ] }
Expand Down Expand Up @@ -61,6 +39,6 @@ class GearedPagination::ControllerTest < ActionController::TestCase

private
def etag_for(*keys)
%(W/"#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(keys))}")
%(W/"#{ActiveSupport::Digest.hexdigest(ActiveSupport::Cache.expand_cache_key(keys))}")
end
end
3 changes: 3 additions & 0 deletions test/dummy/Rakefile
@@ -0,0 +1,3 @@
require_relative 'config/application'

Rails.application.load_tasks
3 changes: 3 additions & 0 deletions test/dummy/app/assets/config/manifest.js
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
Empty file.
15 changes: 15 additions & 0 deletions test/dummy/app/assets/javascripts/application.js
@@ -0,0 +1,15 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require activestorage
//= require_tree .
13 changes: 13 additions & 0 deletions test/dummy/app/assets/javascripts/cable.js
@@ -0,0 +1,13 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
//
//= require action_cable
//= require_self
//= require_tree ./channels

(function() {
this.App || (this.App = {});

App.cable = ActionCable.createConsumer();

}).call(this);
Empty file.
15 changes: 15 additions & 0 deletions test/dummy/app/assets/stylesheets/application.css
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
4 changes: 4 additions & 0 deletions test/dummy/app/channels/application_cable/channel.rb
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions test/dummy/app/channels/application_cable/connection.rb
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/application_controller.rb
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::Base
end
Empty file.
11 changes: 11 additions & 0 deletions test/dummy/app/controllers/recordings_controller.rb
@@ -0,0 +1,11 @@
class RecordingsController < ActionController::Base
def index
set_page_and_extract_portion_from Recording.all, per_page: params[:per_page]
render json: @page.records if stale? etag: "placeholder"
end

def unpaged
@page = "not a geared pagination page"
head :ok if stale? etag: "placeholder"
end
end
2 changes: 2 additions & 0 deletions test/dummy/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions test/dummy/app/jobs/application_job.rb
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
4 changes: 4 additions & 0 deletions test/dummy/app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
3 changes: 3 additions & 0 deletions test/dummy/app/models/application_record.rb
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file.
2 changes: 2 additions & 0 deletions test/dummy/app/models/recording.rb
@@ -0,0 +1,2 @@
class Recording < ApplicationRecord
end
15 changes: 15 additions & 0 deletions test/dummy/app/views/layouts/application.html.erb
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
</head>

<body>
<%= yield %>
</body>
</html>
13 changes: 13 additions & 0 deletions test/dummy/app/views/layouts/mailer.html.erb
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>

<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions test/dummy/app/views/layouts/mailer.text.erb
@@ -0,0 +1 @@
<%= yield %>

0 comments on commit 3a74781

Please sign in to comment.