restfulx 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README.rdoc +3 -3
  2. data/Rakefile +17 -2
  3. data/VERSION.yml +2 -3
  4. data/bin/rx-gen +1 -1
  5. data/ext/restfulx/ext/amf/serializer/extconf.rb +3 -0
  6. data/lib/restfulx.rb +43 -81
  7. data/lib/restfulx/active_record_tasks.rb +8 -6
  8. data/lib/restfulx/active_record_uuid_helper.rb +9 -10
  9. data/lib/restfulx/amf.rb +14 -0
  10. data/lib/restfulx/amf/class_mapping.rb +106 -0
  11. data/lib/restfulx/amf/ext.rb +11 -0
  12. data/lib/restfulx/amf/ext/serializer.bundle +0 -0
  13. data/lib/restfulx/amf/pure.rb +11 -0
  14. data/lib/restfulx/amf/pure/io_helpers.rb +52 -0
  15. data/lib/restfulx/amf/pure/serializer.rb +304 -0
  16. data/lib/restfulx/configuration.rb +16 -12
  17. data/lib/restfulx/{rails/recipes.rb → recipes.rb} +1 -2
  18. data/lib/restfulx/rx_action_controller.rb +34 -0
  19. data/lib/restfulx/rx_active_record.rb +360 -0
  20. data/lib/restfulx/rx_active_support.rb +139 -0
  21. data/lib/restfulx/{datamapper_foo.rb → rx_datamapper.rb} +0 -2
  22. data/lib/restfulx/{rails/schema_to_yaml.rb → schema_to_rx_yaml.rb} +88 -5
  23. data/lib/restfulx/swf_helper.rb +61 -0
  24. data/lib/restfulx/tasks.rb +5 -3
  25. data/rails_generators/rx_config/rx_config_generator.rb +2 -2
  26. data/rails_generators/rx_config/templates/mainapp.mxml +1 -1
  27. data/rails_generators/rx_config/templates/restfulx.erb +5 -3
  28. data/rails_generators/rx_main_app/rx_main_app_generator.rb +2 -2
  29. data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +7 -7
  30. data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +5 -3
  31. data/rxgen_generators/rx_config/rx_config_generator.rb +1 -1
  32. data/test/rails/fixtures/locations.yml +5 -6
  33. data/test/rails/fixtures/notes.yml +5 -15
  34. data/test/rails/fixtures/projects.yml +7 -23
  35. data/test/rails/fixtures/tasks.yml +17 -43
  36. data/test/rails/fixtures/users.yml +7 -11
  37. data/test/rails/helpers/functional_test_helper.rb +5 -4
  38. data/test/rails/helpers/performance_test_helper.rb +5 -0
  39. data/test/rails/helpers/test_helper.rb +27 -0
  40. data/test/rails/helpers/unit_test_helper.rb +3 -15
  41. data/test/rails/test_active_foo.rb +21 -25
  42. data/test/rails/{test_rails_integration_functional.rb → test_notes_controller_functional.rb} +5 -5
  43. data/test/rails/test_serialiazation_performance.rb +32 -0
  44. data/test/rails/test_to_amf.rb +30 -0
  45. data/test/rails/test_to_fxml.rb +18 -15
  46. data/test/rails/test_to_json.rb +2 -14
  47. metadata +30 -19
  48. data/lib/restfulx/active_foo.rb +0 -178
  49. data/lib/restfulx/rails/schema_to_yaml/extensions/enumerable.rb +0 -8
  50. data/lib/restfulx/rails/schema_to_yaml/settings/config.rb +0 -17
  51. data/lib/restfulx/rails/schema_to_yaml/settings/core.rb +0 -73
  52. data/lib/restfulx/rails/swf_helper.rb +0 -59
@@ -34,7 +34,8 @@ class RxYamlScaffoldGenerator < Rails::Generator::Base
34
34
  Rails::Generator::Scripts::Generate.new.run(["rx_scaffold"] + line.split,
35
35
  :flex_only => options[:flex_only],
36
36
  :flex_view_only => options[:flex_view_only],
37
- :rails_only => options[:rails_only])
37
+ :rails_only => options[:rails_only],
38
+ :collision => options[:collision])
38
39
  puts 'done ...'
39
40
  sleep 1
40
41
  end
@@ -44,13 +45,14 @@ class RxYamlScaffoldGenerator < Rails::Generator::Base
44
45
  Rails::Generator::Scripts::Generate.new.run(["rx_scaffold"] + line.split,
45
46
  :flex_only => options[:flex_only],
46
47
  :flex_view_only => options[:flex_view_only],
47
- :rails_only => options[:rails_only])
48
+ :rails_only => options[:rails_only],
49
+ :collision => options[:collision])
48
50
  puts 'done ...'
49
51
  sleep 1
50
52
  end
51
53
  end
52
54
 
53
- Rails::Generator::Scripts::Generate.new.run(["rx_main_app"])
55
+ Rails::Generator::Scripts::Generate.new.run(["rx_main_app"], :collision => options[:collision])
54
56
  end
55
57
  end
56
58
 
@@ -5,7 +5,7 @@ class RxConfigGenerator < RubiGen::Base
5
5
 
6
6
  def manifest
7
7
  record do |m|
8
- framework_release = RestfulX::FRAMEWORK_VERSION
8
+ framework_release = RestfulX::VERSION
9
9
  framework_distribution_url = "http://restfulx.github.com/releases/restfulx-#{framework_release}.swc"
10
10
  framework_destination_file = "lib/restfulx-#{framework_release}.swc"
11
11
 
@@ -1,8 +1,7 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
- vienna:
3
- name: Vienna
4
- user: ludwig
5
2
 
6
- stratford:
7
- name: Stratford Upon Avon
8
- user: shakespeare
3
+ <% for i in 1..1000 %>
4
+ location_<%= i %>:
5
+ name: Location<%= i %>
6
+ user_id: <%= i %>
7
+ <% end %>
@@ -1,17 +1,7 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
2
 
3
- note_one:
4
- content: Note1ContentText
5
- user: user_one
6
-
7
- note_two:
8
- content: Note2ContentText
9
- user: user_two
10
-
11
- note_three:
12
- content: Note3ContentText
13
- user: user_three
14
-
15
- note_four:
16
- content: Note4ContentText
17
- user: user_four
3
+ <% for i in 1..1000 %>
4
+ note_<%= i %>:
5
+ content: SomeNote<%= i %>
6
+ user_id: <%= i %>
7
+ <% end %>
@@ -1,25 +1,9 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
2
 
3
- health:
4
- name: Health
5
- start_date: <%= 20.days.ago %>
6
- completed: false
7
- user: ludwig
8
-
9
- music:
10
- name: Music
11
- start_date: <%= 20.days.ago %>
12
- completed: false
13
- user: ludwig
14
-
15
- hamlet:
16
- name: Hamlet
17
- start_date: <%= 2.years.ago %>
18
- completed: false
19
- user: shakespeare
20
-
21
- othello:
22
- name: Othello
23
- start_date: <%= 20.days.ago %>
24
- completed: false
25
- user: shakespeare
3
+ <% for i in 1..1000 %>
4
+ project_<%= i %>:
5
+ name: Project<%= i %>
6
+ start_date: <%= 20.days.ago %>
7
+ completed: false
8
+ user_id: <%= i %>
9
+ <% end %>
@@ -1,46 +1,20 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
2
 
3
- haydn:
4
- name: Get piano lessons from Haydn
5
- location: vienna
6
- user: ludwig
7
- project: music
8
- start_time: <%= 30.days.ago %>
9
- end_time: <%= 100.days.from_now %>
10
-
11
- salieri:
12
- name: Arrange lessions with Antonio Salieri
13
- location: vienna
14
- user: ludwig
15
- project: music
16
- start_time: <%= 30.days.ago %>
17
-
18
- hearing:
19
- name: See doctor about hearing again
20
- location: vienna
21
- user: ludwig
22
- project: health
23
- start_time: <%= 30.days.ago %>
24
-
25
- sound_board:
26
- name: Get a new sound board made
27
- location: vienna
28
- user: ludwig
29
- project: health
30
- start_time: <%= 30.days.ago %>
31
-
32
- hamlet_soliloquy:
33
- name: "Edit Hamlet's soliloquy"
34
- notes: "'That is the question' or 'is that the question?'"
35
- location: stratford
36
- user: shakespeare
37
- project: hamlet
38
- start_time: <%= 30.days.ago %>
39
-
40
- othello_outline:
41
- name: Outline Othello
42
- location: stratford
43
- user: shakespeare
44
- project: othello
45
- start_time: <%= 30.days.ago %>
3
+ <% for i in 1..1000 %>
4
+ task_one_<%= i %>:
5
+ name: TaskOne<%= i %>
6
+ location_id: <%= i %>
7
+ user_id: <%= i %>
8
+ project_id: <%= i %>
9
+ start_time: <%= 30.days.ago %>
10
+ end_time: <%= 100.days.from_now %>
11
+
12
+ task_two_<%= i %>:
13
+ name: TaskTwo<%= i %>
14
+ location_id: <%= i %>
15
+ user_id: <%= i %>
16
+ project_id: <%= i %>
17
+ start_time: <%= 30.days.ago %>
18
+ end_time: <%= 100.days.from_now %>
19
+ <% end %>
46
20
 
@@ -1,13 +1,9 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
2
 
3
- ludwig:
4
- login: ludwig
5
- first_name: Ludwig
6
- last_name: van Beethoven
7
- email: ludwig@vienna.de
8
-
9
- shakespeare:
10
- login: william
11
- first_name: William
12
- last_name: Shakespeare
13
- email: will@theglobetheater.com
3
+ <% for i in 1..1000 %>
4
+ user_<%= i %>:
5
+ login: user<%= i %>
6
+ first_name: Foo<%= i %>
7
+ last_name: Bar<%= i %>
8
+ email: foo@bar.com
9
+ <% end %>
@@ -3,6 +3,7 @@ $:.unshift(File.dirname(__FILE__) + '/../../lib')
3
3
  schema_file = File.join(File.dirname(__FILE__), '..', 'schema.rb')
4
4
  ENV["RAILS_ENV"] = "test"
5
5
 
6
+ require File.join(File.dirname(__FILE__), 'test_helper')
6
7
  require File.join(File.dirname(__FILE__), '..', 'controllers', 'application_controller')
7
8
  require File.join(File.dirname(__FILE__), '..', 'controllers', 'notes_controller')
8
9
 
@@ -11,11 +12,11 @@ puts "config:\n#{config.inspect}"
11
12
  ActiveRecord::Base.configurations = config
12
13
  ActiveRecord::Base.establish_connection(config)
13
14
 
14
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/models.log")
15
- ActionController::Base.logger = Logger.new(File.dirname(__FILE__) + "/controllers.log")
15
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/../models.log")
16
+ ActionController::Base.logger = Logger.new(File.dirname(__FILE__) + "/../controllers.log")
16
17
  ApplicationController.append_view_path File.join(File.dirname(__FILE__), '..', 'views')
17
18
 
18
19
  load(schema_file) if File.exist?(schema_file)
19
20
 
20
- Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
21
- $:.unshift(Test::Unit::TestCase.fixture_path)
21
+ ActiveSupport::TestCase.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
22
+ $:.unshift(ActiveSupport::TestCase.fixture_path)
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'action_controller/performance_test'
3
+
4
+ ActionController::Base.perform_caching = true
5
+ ActiveSupport::Dependencies.mechanism = :require
@@ -3,7 +3,13 @@ RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined? RAILS_ROOT
3
3
  require 'rubygems'
4
4
  require 'test/unit'
5
5
 
6
+ gem 'activesupport', '= 2.3.2'
7
+ gem 'activerecord', '= 2.3.2'
8
+ gem 'actionpack', '= 2.3.2'
9
+ gem 'rails', '= 2.3.2'
10
+
6
11
  require 'active_support'
12
+ require 'active_support/core_ext'
7
13
  require 'active_support/test_case'
8
14
  require 'active_record'
9
15
  require 'active_record/fixtures'
@@ -11,7 +17,10 @@ require 'action_controller'
11
17
  require 'action_controller/test_case'
12
18
  require 'action_controller/test_process'
13
19
  require 'action_controller/integration'
20
+ require 'action_controller/assertions/selector_assertions'
21
+ require 'action_controller/assertions/response_assertions'
14
22
  require 'sqlite3'
23
+
15
24
  require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'restfulx')
16
25
  require File.join(File.dirname(__FILE__), '..', 'models', 'note')
17
26
  require File.join(File.dirname(__FILE__), '..', 'models', 'user')
@@ -30,6 +39,21 @@ class MockResponse
30
39
 
31
40
  end
32
41
 
42
+ class ActiveSupport::TestCase
43
+ include ActiveRecord::TestFixtures
44
+ include ActionController::TestProcess
45
+ include ActionController::Assertions::SelectorAssertions
46
+ include ActionController::Assertions::ResponseAssertions
47
+
48
+ self.fixture_path = File.join(File.dirname(__FILE__), "../fixtures")
49
+
50
+ self.use_transactional_fixtures = false
51
+ self.use_instantiated_fixtures = false
52
+
53
+ # load up fixtures
54
+ # fixtures :all
55
+ end
56
+
33
57
  class ActiveRecord::TestCase #:nodoc:
34
58
  # Add more helper methods to be used by all tests here...
35
59
 
@@ -51,4 +75,7 @@ class ActiveRecord::TestCase #:nodoc:
51
75
  assert_select(*args, &block)
52
76
  end
53
77
 
78
+ def assert_invalid(record)
79
+ assert !record.valid?
80
+ end
54
81
  end
@@ -4,19 +4,7 @@ $:.unshift(File.dirname(__FILE__) + '/../..')
4
4
  $:.unshift(File.dirname(__FILE__) + '/../../lib')
5
5
  schema_file = File.join(File.dirname(__FILE__), '..', 'schema.rb')
6
6
 
7
- require 'rubygems'
8
- require 'test/unit'
9
-
10
- require 'active_support'
11
- require 'active_support/test_case'
12
- require 'active_record'
13
- require 'active_record/fixtures'
14
- require 'action_controller'
15
- require 'action_controller/test_case'
16
- require 'action_controller/test_process'
17
- require 'action_controller/integration'
18
- require 'sqlite3'
19
-
7
+ require File.join(File.dirname(__FILE__), 'test_helper')
20
8
  require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'restfulx')
21
9
 
22
10
  config = YAML::load(IO.read(File.join(File.dirname(__FILE__), '..', 'database.yml')))[ENV['DB'] || 'test']
@@ -25,5 +13,5 @@ ActiveRecord::Base.establish_connection(config)
25
13
 
26
14
  load(schema_file) if File.exist?(schema_file)
27
15
 
28
- ActiveSupport::TestCase.fixture_path.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
29
- $:.unshift(ActiveSupport::TestCase.fixture_path.fixture_path)
16
+ ActiveSupport::TestCase.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
17
+ $:.unshift(ActiveSupport::TestCase.fixture_path)
@@ -3,34 +3,30 @@ require File.join(File.dirname(__FILE__), 'helpers', 'test_helper')
3
3
  require File.join(File.dirname(__FILE__), 'helpers', 'unit_test_helper')
4
4
 
5
5
  class ActiveFooTest < ActiveRecord::TestCase
6
- fixtures :all
7
-
8
- def setup
9
- @shakespeare = users(:shakespeare)
10
- end
6
+ fixtures :users, :tasks
11
7
 
12
8
  def test_user_fxml
13
- set_response_to users(:ludwig).to_fxml
9
+ set_response_to users(:user_1).to_fxml
14
10
  assert_xml_select 'user'
15
11
  end
16
12
 
17
- def test_task_fxml_has_default_method
18
- set_response_to tasks(:haydn).to_fxml(:methods => :is_active)
19
- assert_xml_select 'task is_active'
20
- end
21
-
22
- def test_user_fxml_includes_tasks
23
- set_response_to users(:ludwig).to_fxml(:include => :tasks)
24
- assert_xml_select 'user tasks task'
25
- end
26
-
27
- def test_user_fxml_has_nothing_to_do_method
28
- set_response_to users(:ludwig).to_fxml(:methods => :has_nothing_to_do)
29
- assert_xml_select 'user has_nothing_to_do'
30
- end
31
-
32
- def test_user_fxml_includes_default_method_from_task
33
- set_response_to users(:ludwig).to_fxml(:methods => :is_active, :include => :tasks)
34
- assert_xml_select 'user tasks task is_active'
35
- end
13
+ # def test_task_fxml_has_default_method
14
+ # set_response_to tasks(:task_one_1).to_fxml(:methods => :is_active)
15
+ # assert_xml_select 'task is_active'
16
+ # end
17
+ #
18
+ # def test_user_fxml_includes_tasks
19
+ # set_response_to users(:user_1).to_fxml(:include => :tasks)
20
+ # assert_xml_select 'user tasks task'
21
+ # end
22
+ #
23
+ # def test_user_fxml_has_nothing_to_do_method
24
+ # set_response_to users(:user_1).to_fxml(:methods => :has_nothing_to_do)
25
+ # assert_xml_select 'user has_nothing_to_do'
26
+ # end
27
+ #
28
+ # def test_user_fxml_includes_default_method_from_task
29
+ # set_response_to users(:user_1).to_fxml(:methods => :is_active, :include => :tasks)
30
+ # assert_xml_select 'user tasks task is_active'
31
+ # end
36
32
  end
@@ -5,7 +5,7 @@ ActionController::Routing::Routes.draw do |map|
5
5
  map.connect ':controller/:action/:id'
6
6
  end
7
7
 
8
- class RailsIntegrationFunctionalTest < ActiveRecord::TestCase
8
+ class NotesControllerFunctionalTest < ActionController::TestCase
9
9
  fixtures :all
10
10
 
11
11
  def setup
@@ -14,9 +14,9 @@ class RailsIntegrationFunctionalTest < ActiveRecord::TestCase
14
14
  @response = ActionController::TestResponse.new
15
15
  end
16
16
 
17
- # def test_render_with_an_empty_params_hash_should_not_blow_up
18
- # get :empty_params_action
19
- # assert_response :success
20
- # end
17
+ def test_render_with_an_empty_params_hash_should_not_blow_up
18
+ get :index
19
+ assert_response :success
20
+ end
21
21
 
22
22
  end
@@ -0,0 +1,32 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'helpers/unit_test_helper'
4
+ require 'helpers/performance_test_helper'
5
+
6
+ class SerializationPerformanceTest < ActionController::PerformanceTest
7
+ fixtures :users
8
+
9
+ def test_all_to_fxml
10
+ users.to_fxml
11
+ end
12
+
13
+ def test_one_to_fxml
14
+ users(:user_1).to_fxml
15
+ end
16
+
17
+ def test_all_to_json
18
+ users.to_json
19
+ end
20
+
21
+ def test_one_to_json
22
+ users(:user_1).to_json
23
+ end
24
+
25
+ def test_all_to_amf
26
+ users.to_amf
27
+ end
28
+
29
+ def test_one_to_amf
30
+ users(:user_1).to_amf
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'helpers/unit_test_helper'
4
+ require 'ruby-prof'
5
+ require 'perftools'
6
+
7
+ class ToAMFTest < ActiveRecord::TestCase
8
+ fixtures :users
9
+
10
+ def test_to_amf_sanity
11
+ assert_nothing_raised { users(:user_1).to_amf }
12
+ end
13
+
14
+ def test_ruby_profile_all_to_amf
15
+ ruby_profile { users.to_amf }
16
+ end
17
+
18
+ def test_perftools_all_to_amf
19
+ PerfTools::CpuProfiler.start("/tmp/to_amf") { users.to_amf }
20
+ end
21
+
22
+ private
23
+ def ruby_profile
24
+ RubyProf.start
25
+ yield
26
+ result = RubyProf.stop
27
+ printer = RubyProf::GraphPrinter.new(result)
28
+ printer.print(STDOUT, 0)
29
+ end
30
+ end