Skip to content

Commit

Permalink
Merge pull request #711 from droberts-ada/rails-5-api
Browse files Browse the repository at this point in the history
Rails 5 API mode compatibility
  • Loading branch information
nesquena committed May 11, 2018
2 parents eb38c01 + eefaf94 commit 27fe47f
Show file tree
Hide file tree
Showing 69 changed files with 857 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
# rake test:setup
# rake test:full

fixture_list = "{padrino_test,sinatra_test,rails2,rails3,rails3_2,rails4,rails5}"
fixture_list = "{padrino_test,sinatra_test,rails2,rails3,rails3_2,rails4,rails5,rails5_api}"

desc "Clean up the fixtures being tested by cleaning and installing dependencies"
task "test:clean" do
Expand Down
37 changes: 36 additions & 1 deletion fixtures/ashared/NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,44 @@ ln -s ../../../../test/integration/rails3_2/users_controller_test.rb test/functi

cd fixtures/rails5
ln -s "../../ashared/models" app/models
ln -s "../../ashared/views/" app/views
ln -s "../../ashared/views_rails_3/" app/views
ln -s "../../ashared/migrate" db/migrate
ln -s "../../ashared/helpers" app/helpers
ln -s "../../../ashared/controllers_rails_5/posts_controller.rb" app/controllers/posts_controller.rb
ln -s "../../../ashared/controllers_rails_5/users_controller.rb" app/controllers/users_controller.rb
ln -s ../../../../test/integration/rails5/posts_controller_test.rb test/functional/posts_controller_test.rb
ln -s ../../../../test/integration/rails5/users_controller_test.rb test/functional/users_controller_test.rb
echo "Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1" >> config/initializers/mime_types.rb
# Do route file?

# Rails 5 API mode

# Basic setup
cd fixtures
rvm use 2.5.0
rails _5.0.2_ new rails5_api --api
cd rails5_api

# Server config
echo "Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1" >> config/initializers/mime_types.rb
cp ../rails5/config/routes.rb config/routes.rb

# Application
rm -r app/models app/views app/migrate
ln -s "../../ashared/models" app/models
ln -s "../../ashared/views_rails_3/" app/views
ln -s "../../ashared/migrate" db/migrate
ln -s "../../ashared/helpers" app/helpers
ln -s "../../../ashared/controllers_rails_5/posts_controller.rb" app/controllers/posts_controller.rb
ln -s "../../../ashared/controllers_rails_5/users_controller.rb" app/controllers/users_controller.rb

# Test setup
cp ../rails5/Rakefile ./
mkdir test/functional
ln -s ../../../../test/integration/rails5/posts_controller_test.rb test/functional/posts_controller_test.rb
ln -s ../../../../test/integration/rails5/users_controller_test.rb test/functional/users_controller_test.rb
cp ../rails5/test/test_helper.rb ./test/test_helper.rb

# Do a bunch of junk with gemfiles and test helpers and such

# end Rails 5 API mode
17 changes: 17 additions & 0 deletions fixtures/ashared/controllers_rails_5/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class PostsController < ApplicationController

respond_to :json, :xml, :html, :rabl_test_v1

def index
@posts = Post.order('id ASC').load
end

def show
@post = Post.find(params[:id])
end

def renderer
post = Post.find(params[:id])
render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context)
end
end
11 changes: 11 additions & 0 deletions fixtures/ashared/controllers_rails_5/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class UsersController < ApplicationController
respond_to :json

def index
@users = User.order('username ASC').load
end

def show
@user = User.find(params[:id])
end
end
17 changes: 0 additions & 17 deletions fixtures/rails5/app/controllers/posts_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions fixtures/rails5/app/controllers/posts_controller.rb
11 changes: 0 additions & 11 deletions fixtures/rails5/app/controllers/users_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions fixtures/rails5/app/controllers/users_controller.rb
1 change: 1 addition & 0 deletions fixtures/rails5/app/helpers
21 changes: 21 additions & 0 deletions fixtures/rails5_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore Byebug command history file.
.byebug_history
46 changes: 46 additions & 0 deletions fixtures/rails5_api/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
source 'https://rubygems.org'

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'pry-rails'
end

group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../")
gem 'riot', :group => "test"
gem 'responders', '~> 2.0'
24 changes: 24 additions & 0 deletions fixtures/rails5_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
13 changes: 13 additions & 0 deletions fixtures/rails5_api/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'
require 'rake/testtask'

Rails.application.load_tasks

Rake::TestTask.new("test:rabl") do |test|
test.pattern = "test/functional/**/*_test.rb"
test.verbose = true
test.warning = false
end
4 changes: 4 additions & 0 deletions fixtures/rails5_api/app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions fixtures/rails5_api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file.
1 change: 1 addition & 0 deletions fixtures/rails5_api/app/controllers/posts_controller.rb
1 change: 1 addition & 0 deletions fixtures/rails5_api/app/controllers/users_controller.rb
1 change: 1 addition & 0 deletions fixtures/rails5_api/app/helpers
2 changes: 2 additions & 0 deletions fixtures/rails5_api/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
4 changes: 4 additions & 0 deletions fixtures/rails5_api/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
1 change: 1 addition & 0 deletions fixtures/rails5_api/app/models
1 change: 1 addition & 0 deletions fixtures/rails5_api/app/views
3 changes: 3 additions & 0 deletions fixtures/rails5_api/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
9 changes: 9 additions & 0 deletions fixtures/rails5_api/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
9 changes: 9 additions & 0 deletions fixtures/rails5_api/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
require_relative '../config/boot'
require 'rake'
Rake.application.run
34 changes: 34 additions & 0 deletions fixtures/rails5_api/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end

puts "\n== Preparing database =="
system! 'bin/rails db:setup'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
17 changes: 17 additions & 0 deletions fixtures/rails5_api/bin/spring
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
require 'rubygems'
require 'bundler'

lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
if spring
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
end
end
29 changes: 29 additions & 0 deletions fixtures/rails5_api/bin/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

puts "\n== Updating database =="
system! 'bin/rails db:migrate'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
5 changes: 5 additions & 0 deletions fixtures/rails5_api/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'

run Rails.application
Loading

0 comments on commit 27fe47f

Please sign in to comment.