roar 0.11.7 → 0.11.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.travis.yml +7 -0
  2. data/CHANGES.markdown +4 -0
  3. data/Rakefile +1 -1
  4. data/gemfiles/Gemfile.representable-1.3 +12 -0
  5. data/lib/roar/representer/json/hal.rb +6 -11
  6. data/lib/roar/version.rb +1 -1
  7. data/test/hal_json_test.rb +24 -25
  8. data/test/hal_links_test.rb +31 -0
  9. data/test/http_verbs_feature_test.rb +2 -1
  10. data/test/hypermedia_test.rb +11 -0
  11. data/test/test_helper.rb +9 -15
  12. metadata +4 -34
  13. data/test/dummy/Rakefile +0 -7
  14. data/test/dummy/app/controllers/albums_controller.rb +0 -27
  15. data/test/dummy/app/controllers/application_controller.rb +0 -4
  16. data/test/dummy/app/helpers/application_helper.rb +0 -2
  17. data/test/dummy/app/models/album.rb +0 -6
  18. data/test/dummy/app/models/song.rb +0 -2
  19. data/test/dummy/app/representers/representer/xml/album.rb +0 -19
  20. data/test/dummy/app/representers/representer/xml/song.rb +0 -9
  21. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  22. data/test/dummy/config.ru +0 -4
  23. data/test/dummy/config/application.rb +0 -20
  24. data/test/dummy/config/boot.rb +0 -10
  25. data/test/dummy/config/database.yml +0 -22
  26. data/test/dummy/config/environment.rb +0 -5
  27. data/test/dummy/config/environments/development.rb +0 -16
  28. data/test/dummy/config/environments/production.rb +0 -46
  29. data/test/dummy/config/environments/test.rb +0 -32
  30. data/test/dummy/config/locales/en.yml +0 -5
  31. data/test/dummy/config/routes.rb +0 -7
  32. data/test/dummy/db/development.sqlite3 +0 -0
  33. data/test/dummy/db/migrate/20110514114753_create_albums.rb +0 -14
  34. data/test/dummy/db/migrate/20110514121228_create_songs.rb +0 -14
  35. data/test/dummy/db/schema.rb +0 -29
  36. data/test/dummy/db/test.sqlite3 +0 -0
  37. data/test/dummy/public/404.html +0 -26
  38. data/test/dummy/public/422.html +0 -26
  39. data/test/dummy/public/500.html +0 -26
  40. data/test/dummy/public/favicon.ico +0 -0
  41. data/test/dummy/script/rails +0 -6
  42. data/test/integration_test.rb +0 -85
  43. data/test/rails/controller_methods_test.rb +0 -147
  44. data/test/rails/rails_representer_methods_test.rb +0 -32
data/.travis.yml CHANGED
@@ -1,3 +1,10 @@
1
1
  rvm: 1.9.3
2
2
  notifications:
3
3
  irc: "irc.freenode.org#cells"
4
+ matrix:
5
+ include:
6
+ - rvm: 1.9.3
7
+ gemfile: gemfiles/Gemfile.representable-1.3
8
+ - rvm: 1.8.7
9
+ gemfile: gemfiles/Gemfile.representable-1.3
10
+
data/CHANGES.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.11.8
2
+
3
+ * Fixed `JSON::HAL::Links` so that it keys links with `links` and not `_links`. The latter is still done by `JSON::HAL`.
4
+
1
5
  ## 0.11.7
2
6
 
3
7
  * Maintenance release: Fixing the horrible bug fix from 0.11.6 and make it a bit less horrible.
data/Rakefile CHANGED
@@ -7,6 +7,6 @@ task :default => [:test]
7
7
 
8
8
  Rake::TestTask.new(:test) do |test|
9
9
  test.libs << 'test'
10
- test.test_files = FileList['test/*_test.rb'] - ['test/integration_test.rb', 'test/active_record_integration_test.rb']
10
+ test.test_files = FileList['test/*_test.rb']
11
11
  test.verbose = true
12
12
  end
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'representable', '1.3.0'
6
+ group :test do
7
+ gem 'faraday'
8
+ gem 'turn'
9
+ gem 'virtus'
10
+ gem "sinatra", "~> 1.3.2"
11
+ gem "sham_rack", "~> 1.3.0"
12
+ end
@@ -48,11 +48,7 @@ module Roar::Representer
48
48
 
49
49
  module ClassMethods
50
50
  def links_definition_options
51
- super.tap { |options| options[1].merge!(
52
- :from => :_links,
53
- :extend => HAL::Links::LinkCollectionRepresenter,
54
- :instance => lambda { |hsh| LinkCollection.new(link_array_rels) }) # defined in InstanceMethods as this is executed in represented context.
55
- }
51
+ super.tap { |options| options[1].merge!(:from => :_links) }
56
52
  end
57
53
  end
58
54
 
@@ -156,13 +152,12 @@ module Roar::Representer
156
152
 
157
153
 
158
154
  module ClassMethods
159
- # TODO: remove Links support in non-HAL.
160
155
  def links_definition_options
161
- super.tap { |options|
162
- options[0] = :links
163
- options[1] = {:class => Feature::Hypermedia::LinkCollection, :extend => LinkCollectionRepresenter, :from => :_links}
164
- }
165
-
156
+ [:links,
157
+ :from => :links,
158
+ :extend => HAL::Links::LinkCollectionRepresenter,
159
+ :instance => lambda { |hsh| LinkCollection.new(link_array_rels) } # defined in InstanceMethods as this is executed in represented context.
160
+ ]
166
161
  end
167
162
 
168
163
  # Use this to define link arrays. It accepts the shared rel attribute and an array of options per link object.
data/lib/roar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roar
2
- VERSION = "0.11.7"
2
+ VERSION = "0.11.8"
3
3
  end
@@ -62,44 +62,43 @@ class HalJsonTest < MiniTest::Spec
62
62
 
63
63
 
64
64
  describe "HAL/JSON" do
65
- before do
66
- Bla = Module.new do
67
- include Roar::Representer::JSON::HAL
68
- property :value
69
- link :self do
70
- "http://items/#{value}"
71
- end
65
+ Bla = Module.new do
66
+ include Roar::Representer::JSON::HAL
67
+ property :title
68
+ link :self do
69
+ "http://songs/#{title}"
72
70
  end
71
+ end
73
72
 
74
- @order_rep = Module.new do
75
- include Roar::Representer::JSON::HAL
76
- property :id
77
- collection :items, :class => Item, :extend => Bla, :embedded => true
78
- link :self do
79
- "http://orders/#{id}"
80
- end
73
+ representer_for([Roar::Representer::JSON::HAL]) do
74
+ property :id
75
+ collection :songs, :class => Song, :extend => Bla, :embedded => true
76
+ link :self do
77
+ "http://albums/#{id}"
81
78
  end
79
+ end
82
80
 
83
- @order = Order.new(:items => [Item.new(:value => "Beer")], :id => 1).extend(@order_rep)
81
+ before do
82
+ @album = Album.new(:songs => [Song.new(:title => "Beer")], :id => 1).extend(rpr)
84
83
  end
85
84
 
86
85
  it "render links and embedded resources according to HAL" do
87
- assert_equal "{\"id\":1,\"_embedded\":{\"items\":[{\"value\":\"Beer\",\"_links\":{\"self\":{\"href\":\"http://items/Beer\"}}}]},\"_links\":{\"self\":{\"href\":\"http://orders/1\"}}}", @order.to_json
86
+ assert_equal "{\"id\":1,\"_embedded\":{\"songs\":[{\"title\":\"Beer\",\"_links\":{\"self\":{\"href\":\"http://songs/Beer\"}}}]},\"_links\":{\"self\":{\"href\":\"http://albums/1\"}}}", @album.to_json
88
87
  end
89
88
 
90
89
  it "parses links and resources following the mighty HAL" do
91
- @order.from_json("{\"id\":2,\"_embedded\":{\"items\":[{\"value\":\"Coffee\",\"_links\":{\"self\":{\"href\":\"http://items/Coffee\"}}}]},\"_links\":{\"self\":{\"href\":\"http://orders/2\"}}}")
92
- assert_equal 2, @order.id
93
- assert_equal "Coffee", @order.items.first.value
94
- assert_equal "http://items/Coffee", @order.items.first.links[:self].href
95
- assert_equal "http://orders/2", @order.links[:self].href
90
+ @album.from_json("{\"id\":2,\"_embedded\":{\"songs\":[{\"title\":\"Coffee\",\"_links\":{\"self\":{\"href\":\"http://songs/Coffee\"}}}]},\"_links\":{\"self\":{\"href\":\"http://albums/2\"}}}")
91
+ assert_equal 2, @album.id
92
+ assert_equal "Coffee", @album.songs.first.title
93
+ assert_equal "http://songs/Coffee", @album.songs.first.links[:self].href
94
+ assert_equal "http://albums/2", @album.links[:self].href
96
95
  end
97
96
 
98
97
  it "doesn't require _links and _embedded to be present" do
99
- @order.from_json("{\"id\":2}")
100
- assert_equal 2, @order.id
101
- assert_equal [], @order.items
102
- @order.links.must_equal({})
98
+ @album.from_json("{\"id\":2}")
99
+ assert_equal 2, @album.id
100
+ assert_equal [], @album.songs
101
+ @album.links.must_equal({})
103
102
  end
104
103
  end
105
104
  end
@@ -0,0 +1,31 @@
1
+ require 'ostruct'
2
+ require 'test_helper'
3
+ require 'roar/representer/json/hal'
4
+
5
+
6
+ class HalLinkTest < MiniTest::Spec
7
+ let(:rpr) do
8
+ Module.new do
9
+ include Roar::Representer::JSON
10
+ include Roar::Representer::JSON::HAL::Links
11
+ link :self do
12
+ "//songs"
13
+ end
14
+ end
15
+ end
16
+
17
+ subject { Object.new.extend(rpr) }
18
+
19
+ describe "#to_json" do
20
+ it "uses 'links' key" do
21
+ assert_equal subject.to_json, "{\"links\":{\"self\":{\"href\":\"//songs\"}}}"
22
+ end
23
+ end
24
+
25
+ describe "#from_json" do
26
+ it "uses 'links' key" do
27
+ subject.from_json("{\"links\":{\"self\":{\"href\":\"//lifer\"}}}").links.values.must_equal [link(:href => "//lifer", :rel => :self)]
28
+ end
29
+ end
30
+ end
31
+
@@ -44,6 +44,7 @@ class HttpVerbsTest < MiniTest::Spec
44
44
  end
45
45
 
46
46
  # FIXME: move to faraday test.
47
+ require 'roar/representer/transport/faraday'
47
48
  describe 'a non-existent resource' do
48
49
  it 'handles HTTP errors and raises a ResourceNotFound error with FaradayHttpTransport' do
49
50
  @band.transport_engine = Roar::Representer::Transport::Faraday
@@ -73,7 +74,7 @@ class HttpVerbsTest < MiniTest::Spec
73
74
  it "updates instance with incoming representation" do
74
75
  @band.name = "Strung Out"
75
76
  assert_equal nil, @band.label
76
-
77
+
77
78
  @band.post("http://roar.example.com/bands", "application/xml")
78
79
  assert_equal "STRUNG OUT", @band.name
79
80
  assert_equal nil, @band.label
@@ -43,6 +43,17 @@ class HypermediaTest < MiniTest::Spec
43
43
  it "receives options when rendering" do
44
44
  subject.to_json(:id => 1).must_equal "{\"links\":[{\"rel\":\"self\",\"href\":\"//self/1\"}]}"
45
45
  end
46
+
47
+ describe "in a composition" do
48
+ representer_for do
49
+ property :entity, :extend => self
50
+ link(:self) { |opts| "//self/#{opts[:id]}" }
51
+ end
52
+
53
+ it "propagates options" do
54
+ Song.new(:entity => Song.new).extend(rpr).to_json(:id => 1).must_equal "{\"entity\":{\"links\":[{\"rel\":\"self\",\"href\":\"//self/1\"}]},\"links\":[{\"rel\":\"self\",\"href\":\"//self/1\"}]}"
55
+ end
56
+ end
46
57
  end
47
58
 
48
59
  describe "returning option hash from block" do
data/test/test_helper.rb CHANGED
@@ -3,6 +3,7 @@ Bundler.setup
3
3
 
4
4
  require 'test/unit'
5
5
  require 'minitest/spec'
6
+ require 'ostruct'
6
7
 
7
8
  require 'roar/representer'
8
9
  require 'roar/representer/feature/http_verbs'
@@ -17,7 +18,7 @@ begin
17
18
  rescue LoadError
18
19
  end
19
20
 
20
- module AttributesConstructor
21
+ module AttributesConstructor # TODO: remove me.
21
22
  def initialize(attrs={})
22
23
  attrs.each do |k,v|
23
24
  instance_variable_set("@#{k}", v)
@@ -25,19 +26,13 @@ module AttributesConstructor
25
26
  end
26
27
  end
27
28
 
28
- class Item
29
- include AttributesConstructor
30
- attr_accessor :value
31
- end
32
-
33
- class Position
34
- include AttributesConstructor
35
- attr_accessor :id, :item
29
+ class Song < OpenStruct
30
+ def ==(other)
31
+ name == other.name and track == other.track
32
+ end
36
33
  end
37
34
 
38
- class Order
39
- include AttributesConstructor
40
- attr_accessor :id, :items
35
+ class Album < OpenStruct
41
36
  end
42
37
 
43
38
  require "test_xml/mini_test"
@@ -55,11 +50,10 @@ MiniTest::Spec.class_eval do
55
50
  Roar::Representer::Feature::Hypermedia::Hyperlink.new(options)
56
51
  end
57
52
 
58
- def self.representer_for(&block) # FIXME: move to test_helper.
53
+ def self.representer_for(modules=[Roar::Representer::JSON, Roar::Representer::Feature::Hypermedia], &block)
59
54
  let (:rpr) do
60
55
  Module.new do
61
- include Roar::Representer::JSON
62
- include Roar::Representer::Feature::Hypermedia
56
+ include *modules.reverse
63
57
 
64
58
  instance_exec(&block)
65
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.7
4
+ version: 0.11.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable
@@ -90,6 +90,7 @@ files:
90
90
  - README.textile
91
91
  - Rakefile
92
92
  - TODO.markdown
93
+ - gemfiles/Gemfile.representable-1.3
93
94
  - lib/roar.rb
94
95
  - lib/roar/representer.rb
95
96
  - lib/roar/representer/feature/client.rb
@@ -106,47 +107,16 @@ files:
106
107
  - test/Gemfile
107
108
  - test/client_test.rb
108
109
  - test/coercion_feature_test.rb
109
- - test/dummy/Rakefile
110
- - test/dummy/app/controllers/albums_controller.rb
111
- - test/dummy/app/controllers/application_controller.rb
112
- - test/dummy/app/helpers/application_helper.rb
113
- - test/dummy/app/models/album.rb
114
- - test/dummy/app/models/song.rb
115
- - test/dummy/app/representers/representer/xml/album.rb
116
- - test/dummy/app/representers/representer/xml/song.rb
117
- - test/dummy/app/views/layouts/application.html.erb
118
- - test/dummy/config.ru
119
- - test/dummy/config/application.rb
120
- - test/dummy/config/boot.rb
121
- - test/dummy/config/database.yml
122
- - test/dummy/config/environment.rb
123
- - test/dummy/config/environments/development.rb
124
- - test/dummy/config/environments/production.rb
125
- - test/dummy/config/environments/test.rb
126
- - test/dummy/config/locales/en.yml
127
- - test/dummy/config/routes.rb
128
- - test/dummy/db/development.sqlite3
129
- - test/dummy/db/migrate/20110514114753_create_albums.rb
130
- - test/dummy/db/migrate/20110514121228_create_songs.rb
131
- - test/dummy/db/schema.rb
132
- - test/dummy/db/test.sqlite3
133
- - test/dummy/public/404.html
134
- - test/dummy/public/422.html
135
- - test/dummy/public/500.html
136
- - test/dummy/public/favicon.ico
137
- - test/dummy/script/rails
138
110
  - test/fake_server.rb
139
111
  - test/faraday_http_transport_test.rb
140
112
  - test/hal_json_test.rb
113
+ - test/hal_links_test.rb
141
114
  - test/http_verbs_feature_test.rb
142
115
  - test/hypermedia_feature_test.rb
143
116
  - test/hypermedia_test.rb
144
- - test/integration_test.rb
145
117
  - test/json_representer_test.rb
146
118
  - test/net_http_transport_test.rb
147
119
  - test/order_representers.rb
148
- - test/rails/controller_methods_test.rb
149
- - test/rails/rails_representer_methods_test.rb
150
120
  - test/representer_test.rb
151
121
  - test/test_helper.rb
152
122
  - test/xml_representer_test.rb
data/test/dummy/Rakefile DELETED
@@ -1,7 +0,0 @@
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
- require 'rake'
6
-
7
- Rails::Application.load_tasks
@@ -1,27 +0,0 @@
1
- require 'roar/rails'
2
-
3
- class AlbumsController < ActionController::Base
4
- include Roar::Rails::ControllerMethods
5
-
6
- respond_to :xml
7
- represents Album
8
-
9
- def show
10
- @album = Album.find(params[:id])
11
- respond_with @album
12
- end
13
-
14
- def create
15
- @album = Album.create(representation)
16
-
17
- respond_with @album
18
- end
19
-
20
- def update
21
- @album = Album.find(params[:id])
22
- @album.songs.delete_all # make PUT behave REST-compliant.
23
- @album.update_attributes(representation)
24
-
25
- respond_with @album
26
- end
27
- end
@@ -1,4 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- layout 'application'
4
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,6 +0,0 @@
1
- class Album < ActiveRecord::Base
2
- has_many :songs
3
- validates_presence_of :year
4
-
5
- accepts_nested_attributes_for :songs, :allow_destroy => true
6
- end
@@ -1,2 +0,0 @@
1
- class Song < ActiveRecord::Base
2
- end
@@ -1,19 +0,0 @@
1
- module Representer
2
- module XML
3
- class Album < Roar::Representer::XML
4
- self.representation_name= :album
5
-
6
- property :id
7
- property :year
8
- collection :songs
9
-
10
- link :self do
11
- album_url(represented.id)
12
- end
13
-
14
- link "album-search" do
15
- album_search_url
16
- end
17
- end
18
- end
19
- end
@@ -1,9 +0,0 @@
1
- module Representer
2
- module XML
3
- class Song < Roar::Representer::XML
4
- self.representation_name= :song
5
-
6
- property :title
7
- end
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
data/test/dummy/config.ru DELETED
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Dummy::Application
@@ -1,20 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require "active_model/railtie"
4
- require "action_controller/railtie"
5
- require "action_view/railtie"
6
- require "active_record/railtie"
7
-
8
- Bundler.require
9
-
10
-
11
- #require "rails_app"
12
-
13
- module Dummy
14
- class Application < Rails::Application
15
- config.encoding = "utf-8"
16
-
17
- # Configure sensitive parameters which will be filtered from the log file.
18
- config.filter_parameters += [:password]
19
- end
20
- end
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
6
- require 'bundler'
7
- Bundler.setup
8
- end
9
-
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,22 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
- development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
8
-
9
- # Warning: The database defined as "test" will be erased and
10
- # re-generated from your development database when you run "rake".
11
- # Do not set this db to the same as development or production.
12
- test:
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
-
18
- production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
@@ -1,16 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.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 webserver when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
- config.action_controller.perform_caching = false
16
- end
@@ -1,46 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.rb
3
-
4
- # The production environment is meant for finished, "live" apps.
5
- # Code is not reloaded between requests
6
- config.cache_classes = true
7
-
8
- # Full error reports are disabled and caching is turned on
9
- config.consider_all_requests_local = false
10
- config.action_controller.perform_caching = true
11
-
12
- # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
-
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
-
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
20
-
21
- # See everything in the log (default is :info)
22
- # config.log_level = :debug
23
-
24
- # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
26
-
27
- # Use a different cache store in production
28
- # config.cache_store = :mem_cache_store
29
-
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
- config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
35
- # config.action_controller.asset_host = "http://assets.example.com"
36
-
37
- # Disable delivery errors, bad email addresses will be ignored
38
- # config.action_mailer.raise_delivery_errors = false
39
-
40
- # Enable threaded mode
41
- # config.threadsafe!
42
-
43
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
- # the I18n.default_locale when a translation can not be found)
45
- config.i18n.fallbacks = true
46
- end
@@ -1,32 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.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
- # Log error messages when you accidentally call methods on nil.
11
- config.whiny_nils = true
12
-
13
- # Show full error reports and disable caching
14
- config.consider_all_requests_local = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Raise exceptions instead of rendering exception templates
18
- config.action_dispatch.show_exceptions = false
19
-
20
- # Disable request forgery protection in test environment
21
- config.action_controller.allow_forgery_protection = false
22
-
23
- # Tell Action Mailer not to deliver emails to the real world.
24
- # The :test delivery method accumulates sent emails in the
25
- # ActionMailer::Base.deliveries array.
26
- #config.action_mailer.delivery_method = :test
27
-
28
- # Use SQL instead of Active Record's schema dumper when creating the test database.
29
- # This is necessary if your schema can't be completely dumped by the schema dumper,
30
- # like if you have constraints or database-specific column types
31
- # config.active_record.schema_format = :sql
32
- end
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
@@ -1,7 +0,0 @@
1
- Dummy::Application.routes.draw do
2
- match ':controller(/:action(/:id(.:format)))'
3
- root :to => 'musician#index'
4
- resources :albums
5
- resources :songs
6
- get "articles/starts_with/{query}", :to => "albums#search",:class => :album_search
7
- end
Binary file
@@ -1,14 +0,0 @@
1
- class CreateAlbums < ActiveRecord::Migration
2
- def self.up
3
- create_table :albums do |t|
4
- t.string :title
5
- t.string :year
6
-
7
- t.timestamps
8
- end
9
- end
10
-
11
- def self.down
12
- drop_table :albums
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- class CreateSongs < ActiveRecord::Migration
2
- def self.up
3
- create_table :songs do |t|
4
- t.string :title
5
- t.integer :album_id
6
-
7
- t.timestamps
8
- end
9
- end
10
-
11
- def self.down
12
- drop_table :songs
13
- end
14
- end
@@ -1,29 +0,0 @@
1
- # This file is auto-generated from the current state of the database. Instead
2
- # of editing this file, please use the migrations feature of Active Record to
3
- # incrementally modify your database, and then regenerate this schema definition.
4
- #
5
- # Note that this schema.rb definition is the authoritative source for your
6
- # database schema. If you need to create the application database on another
7
- # system, you should be using db:schema:load, not running all the migrations
8
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
10
- #
11
- # It's strongly recommended to check this file into your version control system.
12
-
13
- ActiveRecord::Schema.define(:version => 20110514121228) do
14
-
15
- create_table "albums", :force => true do |t|
16
- t.string "title"
17
- t.string "year"
18
- t.datetime "created_at"
19
- t.datetime "updated_at"
20
- end
21
-
22
- create_table "songs", :force => true do |t|
23
- t.string "title"
24
- t.integer "album_id"
25
- t.datetime "created_at"
26
- t.datetime "updated_at"
27
- end
28
-
29
- end
File without changes
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/404.html -->
21
- <div class="dialog">
22
- <h1>The page you were looking for doesn't exist.</h1>
23
- <p>You may have mistyped the address or the page may have moved.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/422.html -->
21
- <div class="dialog">
22
- <h1>The change you wanted was rejected.</h1>
23
- <p>Maybe you tried to change something you didn't have access to.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/500.html -->
21
- <div class="dialog">
22
- <h1>We're sorry, but something went wrong.</h1>
23
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
- </div>
25
- </body>
26
- </html>
File without changes
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,85 +0,0 @@
1
- require 'test_helper'
2
- require 'roar/representer/json'
3
- require 'roar/representer/feature/hypermedia'
4
-
5
- class IntegrationTest < MiniTest::Spec
6
- class Beer
7
- include Roar::Representer::JSON
8
- include Roar::Representer::Feature::Hypermedia
9
-
10
- property :name
11
-
12
- link :self do
13
- "http://beers/#{name.downcase}"
14
- end
15
- end
16
-
17
- class Beers
18
- include Roar::Representer::JSON
19
- include Roar::Representer::Feature::Hypermedia
20
-
21
- collection :items, :class => Beer
22
- end
23
-
24
- describe "Beer service" do
25
- it "provides a document for a particular beer" do
26
- assert_equal "{\"beer\":{\"name\":\"Eisenbahn\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/eisenbahn\"}]}}", Beer.from_attributes(name: "Eisenbahn").to_json
27
- end
28
-
29
- it "provides a detailed beers list" do
30
- beers = ["Jever", "Becks", "Eisenbahn", "Colorado"].collect do |name|
31
- Beer.from_attributes(name: name)
32
- end
33
-
34
-
35
- list = Beers.new
36
- list.items = beers
37
-
38
- assert_equal "{\"beers\":{\"items\":[{\"name\":\"Jever\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/jever\"}]},{\"name\":\"Becks\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/becks\"}]},{\"name\":\"Eisenbahn\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/eisenbahn\"}]},{\"name\":\"Colorado\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/colorado\"}]}]}}", list.to_json
39
- end
40
-
41
- it "provides a pageable beers list without details" do
42
- class BeerCollection
43
- include Roar::Representer::JSON
44
- include Roar::Representer::Feature::Hypermedia
45
-
46
- attr_accessor :per_page, :current_page, :all_items
47
-
48
- collection :beers, :class => Beer
49
- property :total
50
-
51
- def total
52
- all_items.size
53
- end
54
-
55
- def beers
56
- all_items[(current_page-1)*per_page..current_page*per_page-1]
57
- end
58
-
59
- link :next do
60
- "http://beers/all?page=#{current_page+1}" if current_page < total / per_page
61
- end
62
-
63
- link :prev do
64
- "http://beers/all?page=#{current_page-1}" if current_page > 1
65
- end
66
- end
67
-
68
- beers = ["Jever", "Becks", "Eisenbahn", "Colorado"].collect do |name|
69
- Beer.from_attributes(name: name)
70
- end
71
-
72
-
73
- list = BeerCollection.new
74
- list.all_items = beers # this would be a AR collection from a #find.
75
- list.current_page = 1
76
- list.per_page = 2
77
-
78
- assert_equal "{\"beer_collection\":{\"beers\":[{\"name\":\"Jever\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/jever\"}]},{\"name\":\"Becks\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/becks\"}]}],\"total\":4,\"links\":[{\"rel\":\"next\",\"href\":\"http://beers/all?page=2\"},{\"rel\":\"prev\"}]}}", list.to_json
79
-
80
-
81
- list.current_page = 2
82
- assert_equal "{\"beer_collection\":{\"beers\":[{\"name\":\"Eisenbahn\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/eisenbahn\"}]},{\"name\":\"Colorado\",\"links\":[{\"rel\":\"self\",\"href\":\"http://beers/colorado\"}]}],\"total\":4,\"links\":[{\"rel\":\"next\"},{\"rel\":\"prev\",\"href\":\"http://beers/all?page=1\"}]}}", list.to_json
83
- end
84
- end
85
- end
@@ -1,147 +0,0 @@
1
- require 'test_helper'
2
- require 'roar/rails/test_case'
3
- require "dummy/config/environment"
4
- require "rails/test_help" # adds stuff like @routes, etc.
5
-
6
- module Representer
7
- module BMP
8
- class Album; end
9
- end
10
- end
11
-
12
- class ControllerMethodsTest < ActionController::TestCase
13
- tests AlbumsController
14
-
15
- test "responds to #responder" do
16
- assert_equal Roar::Rails::ControllerMethods::Responder, @controller.class.responder
17
- end
18
-
19
- test "responds to #represents" do
20
- @controller = Class.new(AlbumsController)
21
- assert_equal Album, @controller.represented_class
22
- @controller.represents Song
23
- assert_equal Song, @controller.represented_class
24
- end
25
-
26
- test "responds to #representer_class_for" do
27
- assert_equal Representer::BMP::Album, @controller.representer_class_for(Album, :bmp)
28
- end
29
-
30
- test "responds to #representation" do
31
- post :create, %{<album>
32
- <year>2011</year>
33
- <song>
34
- <title>Walking In Your Footsteps</title>
35
- </song>
36
- </album>}, :format => :xml
37
-
38
-
39
- assert_equal({"id"=>"", "year"=>"2011",
40
- "songs_attributes"=>[{"title"=>"Walking In Your Footsteps"}]}, @controller.representation)
41
- end
42
-
43
- test "responds to #incoming" do
44
- post :create, %{<album>
45
- <year>2011</year>
46
- <song>
47
- <title>Walking In Your Footsteps</title>
48
- </song>
49
- </album>}, :format => :xml
50
-
51
-
52
- assert_equal({"id"=>"", "year"=>"2011",
53
- "songs"=>[{"title"=>"Walking In Your Footsteps"}], "links"=>[]}, @controller.incoming.to_attributes)
54
- end
55
- end
56
-
57
-
58
- class ControllerFunctionalTest < ActionController::TestCase
59
- tests AlbumsController
60
-
61
- test "GET: returns a xml representation" do
62
- get :show, :id => 1, :format => :xml
63
-
64
- assert_response 200
65
- assert_body %{
66
- <album>
67
- <id>1</id>
68
- <year>2011</year>
69
- <song>
70
- <title>Alltax</title>
71
- </song>
72
- <song>
73
- <title>Bali</title>
74
- </song>
75
-
76
- <link rel="self" href="http://test.host/albums/1" />
77
- <link rel="album-search" href="http://test.host/articles/starts_with/{query}" />
78
- </album>}, :format => :xml
79
- end
80
-
81
- test "POST: creates a new album and returns the xml representation" do
82
- post :create, %{<album>
83
- <year>1997</year>
84
- <song>
85
- <title>Cooler Than You</title>
86
- </song>
87
- </album>}, :format => :xml
88
-
89
- assert @album = Album.find(:last)
90
- assert_equal "1997", @album.year
91
- assert_equal "Cooler Than You", @album.songs.first.title
92
-
93
- assert_response 201, "Location" => album_url(@album) # Created
94
- assert_body %{
95
- <album>
96
- <id>2</id>
97
- <year>1997</year>
98
- <song>
99
- <title>Cooler Than You</title>
100
- </song>
101
-
102
- <link rel="self" href="http://test.host/albums/2" />
103
- <link rel="album-search" href="http://test.host/articles/starts_with/{query}" />
104
- </album>}, :format => :xml
105
- end
106
-
107
- test "POST: invalid incoming representations yields to 422" do
108
- post :create, :format => :xml
109
-
110
- assert_response 422 # Unprocessable Entity
111
- end
112
-
113
- test "PUT: updates album and returns the xml representation" do
114
- put :update, %{
115
- <album>
116
- <year>1997</year>
117
- <song>
118
- <title>Cooler Than You</title>
119
- </song>
120
- <song>
121
- <title>Rubbing The Elf</title>
122
- </song>
123
- </album>}, :id => 1, :format => :xml
124
-
125
- assert @album = Album.find(1)
126
- assert_equal "1997", @album.year
127
- assert_equal 2, @album.songs.size
128
- assert_equal "Cooler Than You", @album.songs.first.title
129
- assert_equal "Rubbing The Elf", @album.songs.last.title
130
-
131
- assert_response 200
132
- assert_body %{
133
- <album>
134
- <id>1</id>
135
- <year>1997</year>
136
- <song>
137
- <title>Cooler Than You</title>
138
- </song>
139
- <song>
140
- <title>Rubbing The Elf</title>
141
- </song>
142
-
143
- <link rel="self" href="http://test.host/albums/1" />
144
- <link rel="album-search" href="http://test.host/articles/starts_with/{query}" />
145
- </album>}, :format => :xml
146
- end
147
- end
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
- require "dummy/config/environment"
3
- require 'roar/rails'
4
-
5
- module Representer
6
- module JPG
7
- class Song; end
8
- class Album < Roar::Representer::XML; end
9
- end
10
- end
11
-
12
-
13
-
14
- class RailsRepresenterMethodsTest < MiniTest::Spec
15
- describe "Rails::RepresenterMethods" do
16
- before do
17
- @c = Representer::JPG::Album # TODO: mix Rails into Base, not XML only.
18
- end
19
-
20
- it "provides conventions for #collection" do
21
- @c.collection :songs
22
-
23
- @d = @c.representable_attrs.first
24
- assert_equal Representer::JPG::Song, @d.sought_type
25
- assert @d.array?
26
- end
27
-
28
- it "provides conventions for #representation_name" do
29
- assert_equal "album", @c.representation_name
30
- end
31
- end
32
- end