Skip to content

Commit

Permalink
[api] test HTML in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Oct 22, 2013
1 parent 8c2d4cd commit a152b7e
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 14 deletions.
18 changes: 16 additions & 2 deletions src/api/Gemfile
Expand Up @@ -2,8 +2,7 @@
# This preamble is the current preamble for Rails 3 apps; edit as needed.
source 'https://rubygems.org'

gem 'rails-api'
gem 'activerecord', '~> 4.0'
gem 'rails', '~> 4.0'
gem 'actionmailer'

gem 'mysql2'
Expand Down Expand Up @@ -61,3 +60,18 @@ end
group :development do
gem 'pry', '>= 0.9.12'
end

# Gems used only for assets and not required in production environments by default.
group :assets do
gem 'cssmin', '>= 1.0.2'
gem 'uglifier', '>= 1.2.2'
gem 'sass-rails'
gem 'jquery-datatables-rails'
gem 'codemirror-rails', '>= 3.13'
gem 'rails_tokeninput', '>= 1.6.1.rc1'
gem 'sprite-factory', '>= 1.5.2'
gem 'chunky_png'

gem "bootstrap-sass"
end

58 changes: 52 additions & 6 deletions src/api/Gemfile.lock
Expand Up @@ -28,15 +28,21 @@ GEM
addressable (2.3.5)
arel (4.0.0)
atomic (1.1.14)
bootstrap-sass (2.3.2.2)
sass (~> 3.2)
builder (3.1.4)
chunky_png (1.2.8)
ci_reporter (1.9.0)
builder (>= 2.1.2)
clockwork (0.6.1)
activesupport
tzinfo (~> 0.3.35)
codemirror-rails (3.16)
railties (>= 3.0, < 5)
coderay (1.0.9)
crack (0.4.1)
safe_yaml (~> 0.9.0)
cssmin (1.0.3)
daemons (1.1.9)
dalli (2.6.4)
database_cleaner (1.2.0)
Expand All @@ -46,16 +52,23 @@ GEM
activerecord (>= 3.0, < 4.1)
delayed_job (>= 3.0, < 4.1)
erubis (2.7.0)
execjs (2.0.2)
faker (1.2.0)
i18n (~> 0.5)
flog (4.1.2)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.0)
hike (1.2.3)
hoptoad_notifier (2.4.11)
activesupport
builder
i18n (0.6.5)
innertube (1.1.0)
jquery-datatables-rails (1.11.2)
jquery-rails
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.0)
mail (2.5.4)
mime-types (~> 1.16)
Expand All @@ -81,10 +94,16 @@ GEM
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails-api (0.1.0)
actionpack (>= 3.2.11)
railties (>= 3.2.11)
tzinfo (~> 0.3.31)
rails (4.0.0)
actionmailer (= 4.0.0)
actionpack (= 4.0.0)
activerecord (= 4.0.0)
activesupport (= 4.0.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.0)
sprockets-rails (~> 2.0.0)
rails_tokeninput (1.6.1.rc1)
railties (>= 3.1.0)
railties (4.0.0)
actionpack (= 4.0.0)
activesupport (= 4.0.0)
Expand All @@ -98,6 +117,11 @@ GEM
ruby_parser (3.2.2)
sexp_processor (~> 4.1)
safe_yaml (0.9.7)
sass (3.2.12)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
sexp_processor (4.3.0)
simplecov (0.7.1)
multi_json (~> 1.0)
Expand All @@ -106,6 +130,16 @@ GEM
simplecov-rcov (0.2.3)
simplecov (>= 0.4.1)
slop (3.4.6)
sprite-factory (1.5.3)
sprockets (2.10.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
thinking-sphinx (3.0.4)
activerecord (>= 3.1.0)
builder (>= 2.1.2)
Expand All @@ -115,11 +149,15 @@ GEM
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
timecop (0.6.3)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
uglifier (2.2.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
webmock (1.13.0)
addressable (>= 2.2.7)
crack (>= 0.3.2)
Expand All @@ -132,28 +170,36 @@ PLATFORMS

DEPENDENCIES
actionmailer
activerecord (~> 4.0)
bootstrap-sass
chunky_png
ci_reporter
clockwork
codemirror-rails (>= 3.13)
cssmin (>= 1.0.2)
daemons
dalli
database_cleaner (>= 1.0.1)
delayed_job_active_record (>= 4.0.0)
faker
flog (> 4.1.0)
hoptoad_notifier (~> 2.3)
jquery-datatables-rails
minitest (< 5.0)
minitest-colorize
mysql2
newrelic_rpm
nokogiri (~> 1.6.0)
pry (>= 0.9.12)
rails-api
rails (~> 4.0)
rails_tokeninput (>= 1.6.1.rc1)
rdoc
ruby-ldap
sass-rails
simplecov-rcov
sprite-factory (>= 1.5.2)
thinking-sphinx (= 3.0.4)
timecop
uglifier (>= 1.2.2)
webmock (>= 1.9.0)
xmlhash (>= 1.3.6)
yajl-ruby
2 changes: 2 additions & 0 deletions src/api/app/assets/javascripts/html/main.js
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
3 changes: 3 additions & 0 deletions src/api/app/assets/stylesheets/html/main.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Html::Main controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
2 changes: 1 addition & 1 deletion src/api/app/controllers/application_controller.rb
Expand Up @@ -6,7 +6,7 @@
require_dependency 'opensuse/validator'
require_dependency 'api_exception'

class ApplicationController < ActionController::API
class ApplicationController < ActionController::Base

class InvalidHttpMethodError < APIException
setup 'invalid_http_method'
Expand Down
6 changes: 6 additions & 0 deletions src/api/app/controllers/html/main_controller.rb
@@ -0,0 +1,6 @@
class Html::MainController < ApplicationController

def index
@messages = StatusMessage.alive
end
end
2 changes: 2 additions & 0 deletions src/api/app/helpers/html/main_helper.rb
@@ -0,0 +1,2 @@
module Html::MainHelper
end
5 changes: 5 additions & 0 deletions src/api/app/views/html/main/index.html.erb
@@ -0,0 +1,5 @@
<h2>hallo</h2>

<% @messages.each do |m| %>
<div><%= m.inspect %></div>
<% end %>
26 changes: 26 additions & 0 deletions src/api/app/views/layouts/application.html.erb
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Rails Bootstrap" %></title>
<meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Rails Bootstrap" %>">
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<main role="main">
<div class="container">
<div class="content">
<div class="row">
<div class="span12">
<%= yield %>
</div>
</div>
<footer>
</footer>
</div>
</div>
</main>
</body>
</html>
10 changes: 6 additions & 4 deletions src/api/config/routes.rb
@@ -1,5 +1,11 @@
OBSApi::Application.routes.draw do

scope constraints: { format: 'html' } do
namespace :html do
get '/' => 'main#index'
end
end

defaults :format => 'xml' do

get '/' => 'main#index'
Expand Down Expand Up @@ -380,9 +386,5 @@

get '/404' => 'main#notfound'

# Do not install default routes for maximum security
#get ':controller(/:action(/:id))'
#get ':controller/:action'

end
end
2 changes: 1 addition & 1 deletion src/api/lib/opensuse/validator.rb
Expand Up @@ -6,7 +6,7 @@
# on the request type (GET, PUT, POST, etc.) and direction (in, out). Supported schema
# types are RelaxNG and XML Schema (xsd).
module ActionController
class API
class Base

class << self
# Method for mapping actions in a controller to (XML) schemas based on request
Expand Down
7 changes: 7 additions & 0 deletions src/api/test/controllers/html/main_controller_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class Html::MainControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
4 changes: 4 additions & 0 deletions src/api/test/helpers/html/main_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class Html::MainHelperTest < ActionView::TestCase
end

0 comments on commit a152b7e

Please sign in to comment.