roar-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,29 @@
1
+ # roar-rails
2
+
3
+ _Makes using Roar's representers in your Rails app fun._
4
+
5
+ ## Features
6
+
7
+ ### URL Helpers
8
+
9
+ Any URL helpers from the Rails app are automatically available in representers.
10
+
11
+ ```ruby
12
+ module FruitRepresenter
13
+ include Roar::Representer::JSON
14
+
15
+ link :self do
16
+ fruit_url self
17
+ end
18
+ ```
19
+
20
+ ### Testing
21
+
22
+ ### Autoloading
23
+
24
+
25
+
26
+
27
+ ## Contributors
28
+
29
+ * [Railslove](http://www.railslove.de) and especially Michael Bumann [bumi] have heavily supported development of roar-rails ("resource :singers").
data/lib/roar-rails.rb CHANGED
@@ -1,4 +1,16 @@
1
1
  require "roar/rails/version"
2
+ require "roar/representer"
3
+ require "roar/rails/railtie"
4
+
5
+ module Roar::Representer
6
+ autoload("JSON", "roar/representer/json")
7
+
8
+ module Feature
9
+ autoload("Hypermedia", "roar/representer/feature/hypermedia")
10
+ end
11
+ end
12
+
13
+
2
14
 
3
15
  module Roar
4
16
  module Rails
@@ -0,0 +1,19 @@
1
+ require "rails/railtie"
2
+ require "roar/rails/url_methods"
3
+
4
+ module Roar
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+ config.representer = ActiveSupport::OrderedOptions.new
8
+
9
+ initializer "roar.set_configs" do |app|
10
+ ::Roar::Representer.module_eval do
11
+ include app.routes.url_helpers
12
+ include app.routes.mounted_helpers
13
+
14
+ include UrlMethods # provide an initial #default_url_options.
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,7 +2,7 @@ module Roar
2
2
  module Rails
3
3
  module TestCase
4
4
  def get(action, *args)
5
- process(action, "GET", nil, *args)
5
+ process(action, "GET", *args)
6
6
  end
7
7
 
8
8
  def post(action, *args)
@@ -18,8 +18,14 @@ module Roar
18
18
  end
19
19
 
20
20
  def process(action, http_method, document="", params={})
21
+ if document.is_a?(Hash)
22
+ params = document
23
+ document = ""
24
+ end
25
+
21
26
  request.env['RAW_POST_DATA'] = document
22
- super(action, params, nil, nil, http_method)
27
+
28
+ super(action, params, nil, nil, http_method) # FIXME: for Rails <=3.1, only.
23
29
  end
24
30
 
25
31
  module Assertions
@@ -0,0 +1,9 @@
1
+ # Note: this file might be removed soon.
2
+
3
+ module Roar::Rails
4
+ module UrlMethods
5
+ def default_url_options
6
+ Rails.application.config.representer.default_url_options
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Roar
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/roar-rails.gemspec CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_runtime_dependency "roar", "~> 0.9.1"
22
22
  s.add_runtime_dependency "test_xml"
23
+ s.add_runtime_dependency "actionpack", "~> 3.0"
24
+ s.add_runtime_dependency "railties", "~> 3.0"
23
25
 
24
26
  s.add_development_dependency "minitest", ">= 2.8.1"
25
- s.add_development_dependency "actionpack", "~> 3.0"
26
- s.add_dependency "railties", "~> 3.0"
27
27
  s.add_development_dependency "tzinfo" # FIXME: why the hell do we need this for 3.1?
28
28
  end
@@ -0,0 +1,8 @@
1
+ Musician = Struct.new(:name)
2
+
3
+ class SingersController < ActionController::Base
4
+ def show
5
+ singer = Musician.new("Bumi")
6
+ render :text => singer.extend(SingerRepresenter).to_json
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module SingerRepresenter
2
+ include Roar::Representer::JSON
3
+ include Roar::Representer::Feature::Hypermedia
4
+
5
+ property :name
6
+
7
+ link :self do
8
+ singer_url(name)
9
+ end
10
+ end
@@ -29,4 +29,6 @@ Dummy::Application.configure do
29
29
  # This is necessary if your schema can't be completely dumped by the schema dumper,
30
30
  # like if you have constraints or database-specific column types
31
31
  # config.active_record.schema_format = :sql
32
+
33
+ config.representer.default_url_options = {:host => "http://roar.apotomo.de"}
32
34
  end
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
2
  match ':controller(/:action(/:id(.:format)))'
3
3
  root :to => 'musician#index'
4
+ resources :singers
4
5
  end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class RepresenterTest < ActionController::TestCase
4
+ include Roar::Rails::TestCase
5
+
6
+ tests SingersController
7
+
8
+ test "representers can use URL helpers" do
9
+ get :show, :id => "bumi"
10
+ assert_body "{\"name\":\"Bumi\",\"links\":[{\"rel\":\"self\",\"href\":\"http://http://roar.apotomo.de/singers/Bumi\"}]}"
11
+
12
+ end
13
+ end
@@ -1,10 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
- ENV['RAILS_ENV'] = 'test'
4
- require "dummy/config/environment"
5
- require "rails/test_help" # adds stuff like @routes, etc.
6
- require "roar/rails/test_case"
7
-
8
3
  class TestCaseTest < ActionController::TestCase
9
4
  include Roar::Rails::TestCase
10
5
 
@@ -22,6 +17,11 @@ class TestCaseTest < ActionController::TestCase
22
17
  assert_equal "", response.body
23
18
  end
24
19
 
20
+ test "allows POST with options, only" do
21
+ post :show, :id => 1
22
+ assert_equal "1", response.body
23
+ end
24
+
25
25
  test "allows POST with document" do
26
26
  post :show, "{}"
27
27
  assert_equal "{}", response.body
data/test/test_helper.rb CHANGED
@@ -3,3 +3,8 @@ Bundler.setup
3
3
 
4
4
  require 'test/unit'
5
5
  require 'minitest/spec'
6
+
7
+ ENV['RAILS_ENV'] = 'test'
8
+ require "dummy/config/environment"
9
+ require "rails/test_help" # adds stuff like @routes, etc.
10
+ require "roar/rails/test_case"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-01-03 00:00:00 +01:00
17
+ date: 2012-01-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -46,22 +46,21 @@ dependencies:
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: minitest
49
+ name: actionpack
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
- - - ">="
54
+ - - ~>
55
55
  - !ruby/object:Gem::Version
56
56
  segments:
57
- - 2
58
- - 8
59
- - 1
60
- version: 2.8.1
61
- type: :development
57
+ - 3
58
+ - 0
59
+ version: "3.0"
60
+ type: :runtime
62
61
  version_requirements: *id003
63
62
  - !ruby/object:Gem::Dependency
64
- name: actionpack
63
+ name: railties
65
64
  prerelease: false
66
65
  requirement: &id004 !ruby/object:Gem::Requirement
67
66
  none: false
@@ -72,21 +71,22 @@ dependencies:
72
71
  - 3
73
72
  - 0
74
73
  version: "3.0"
75
- type: :development
74
+ type: :runtime
76
75
  version_requirements: *id004
77
76
  - !ruby/object:Gem::Dependency
78
- name: railties
77
+ name: minitest
79
78
  prerelease: false
80
79
  requirement: &id005 !ruby/object:Gem::Requirement
81
80
  none: false
82
81
  requirements:
83
- - - ~>
82
+ - - ">="
84
83
  - !ruby/object:Gem::Version
85
84
  segments:
86
- - 3
87
- - 0
88
- version: "3.0"
89
- type: :runtime
85
+ - 2
86
+ - 8
87
+ - 1
88
+ version: 2.8.1
89
+ type: :development
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: tzinfo
@@ -113,15 +113,19 @@ extra_rdoc_files: []
113
113
  files:
114
114
  - .gitignore
115
115
  - Gemfile
116
+ - README.markdown
116
117
  - Rakefile
117
118
  - lib/roar-rails.rb
119
+ - lib/roar/rails/railtie.rb
118
120
  - lib/roar/rails/test_case.rb
121
+ - lib/roar/rails/url_methods.rb
119
122
  - lib/roar/rails/version.rb
120
123
  - roar-rails.gemspec
121
124
  - test/dummy/Rakefile
122
125
  - test/dummy/app/controllers/application_controller.rb
123
- - test/dummy/app/controllers/musician_controller.rb
126
+ - test/dummy/app/controllers/singers_controller.rb
124
127
  - test/dummy/app/helpers/application_helper.rb
128
+ - test/dummy/app/representers/singer_representer.rb
125
129
  - test/dummy/app/views/layouts/application.html.erb
126
130
  - test/dummy/app/views/musician/featured.html.erb
127
131
  - test/dummy/app/views/musician/featured_with_block.html.erb
@@ -151,6 +155,7 @@ files:
151
155
  - test/dummy/script/rails
152
156
  - test/dummy/tmp/app/cells/blog/post/latest.html.erb
153
157
  - test/dummy/tmp/app/cells/blog/post_cell.rb
158
+ - test/representer_test.rb
154
159
  - test/test_case_test.rb
155
160
  - test/test_helper.rb
156
161
  has_rdoc: true
@@ -1,36 +0,0 @@
1
- class MusicianController < ActionController::Base
2
- def index
3
- render :text => render_cell(:bassist, :promote)
4
- end
5
-
6
- def promote
7
- render :text => render_cell(:trumpeter, :promote)
8
- end
9
-
10
- def promotion
11
- render :text => render_cell(:bassist, :provoke)
12
- end
13
-
14
- def featured
15
- end
16
-
17
- def featured_with_block
18
- end
19
-
20
- def skills
21
- render :text => render_cell(:bassist, :listen)
22
- end
23
-
24
- def hamlet
25
- end
26
-
27
- attr_reader :flag
28
- def promotion_with_block
29
- html = render_cell(:bassist, :play) do |cell|
30
- @flag = cell.class
31
- end
32
-
33
- render :text => html
34
- end
35
-
36
- end