restfulx 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +127 -0
  3. data/README.rdoc +50 -0
  4. data/Rakefile +42 -0
  5. data/app_generators/rx_app/USAGE +22 -0
  6. data/app_generators/rx_app/rx_app_generator.rb +94 -0
  7. data/app_generators/rx_app/templates/actionscript.properties +16 -0
  8. data/app_generators/rx_app/templates/actionscriptair.properties +16 -0
  9. data/app_generators/rx_app/templates/app.yaml.erb +12 -0
  10. data/app_generators/rx_app/templates/default_tasks.rake +51 -0
  11. data/app_generators/rx_app/templates/empty.txt +0 -0
  12. data/app_generators/rx_app/templates/expressInstall.swf +0 -0
  13. data/app_generators/rx_app/templates/flex.properties +2 -0
  14. data/app_generators/rx_app/templates/generate.rb +17 -0
  15. data/app_generators/rx_app/templates/html-template/AC_OETags.js +276 -0
  16. data/app_generators/rx_app/templates/html-template/history/history.css +6 -0
  17. data/app_generators/rx_app/templates/html-template/history/history.js +645 -0
  18. data/app_generators/rx_app/templates/html-template/history/historyFrame.html +29 -0
  19. data/app_generators/rx_app/templates/html-template/index.template.html +121 -0
  20. data/app_generators/rx_app/templates/html-template/playerProductInstall.swf +0 -0
  21. data/app_generators/rx_app/templates/index.html.erb +18 -0
  22. data/app_generators/rx_app/templates/index.yaml +11 -0
  23. data/app_generators/rx_app/templates/mainair-app.xml +134 -0
  24. data/app_generators/rx_app/templates/mainapp-config.xml +21 -0
  25. data/app_generators/rx_app/templates/mainapp.mxml +31 -0
  26. data/app_generators/rx_app/templates/project-textmate.erb +52 -0
  27. data/app_generators/rx_app/templates/project.properties +18 -0
  28. data/app_generators/rx_app/templates/projectair.properties +24 -0
  29. data/app_generators/rx_app/templates/swfobject.js +5 -0
  30. data/bin/rx-gen +31 -0
  31. data/generators/rx_config/USAGE +5 -0
  32. data/generators/rx_config/rx_config_generator.rb +19 -0
  33. data/generators/rx_controller/USAGE +10 -0
  34. data/generators/rx_controller/rx_controller_generator.rb +39 -0
  35. data/generators/rx_controller/templates/assist.py +65 -0
  36. data/generators/rx_controller/templates/controller.as.erb +36 -0
  37. data/generators/rx_controller/templates/restful.py +136 -0
  38. data/generators/rx_main_app/USAGE +8 -0
  39. data/generators/rx_main_app/rx_main_app_generator.rb +60 -0
  40. data/generators/rx_main_app/templates/main.py.erb +29 -0
  41. data/generators/rx_main_app/templates/mainapp.mxml +35 -0
  42. data/generators/rx_scaffold/USAGE +29 -0
  43. data/generators/rx_scaffold/rx_scaffold_generator.rb +146 -0
  44. data/generators/rx_scaffold/templates/component.mxml.erb +149 -0
  45. data/generators/rx_scaffold/templates/controller.py.erb +27 -0
  46. data/generators/rx_scaffold/templates/model.as.erb +42 -0
  47. data/generators/rx_scaffold/templates/model.py.erb +14 -0
  48. data/generators/rx_yaml_scaffold/USAGE +45 -0
  49. data/generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +47 -0
  50. data/lib/restfulx/active_foo.rb +186 -0
  51. data/lib/restfulx/active_record_tasks.rb +81 -0
  52. data/lib/restfulx/configuration.rb +76 -0
  53. data/lib/restfulx/datamapper_foo.rb +31 -0
  54. data/lib/restfulx/rails/recipes.rb +60 -0
  55. data/lib/restfulx/rails/swf_helper.rb +60 -0
  56. data/lib/restfulx/tasks.rb +85 -0
  57. data/lib/restfulx.rb +117 -0
  58. data/rails_generators/rx_config/USAGE +18 -0
  59. data/rails_generators/rx_config/rx_config_generator.rb +115 -0
  60. data/rails_generators/rx_config/templates/actionscript.properties +16 -0
  61. data/rails_generators/rx_config/templates/actionscriptair.properties +16 -0
  62. data/rails_generators/rx_config/templates/expressInstall.swf +0 -0
  63. data/rails_generators/rx_config/templates/flex.properties +2 -0
  64. data/rails_generators/rx_config/templates/html-template/AC_OETags.js +276 -0
  65. data/rails_generators/rx_config/templates/html-template/history/history.css +6 -0
  66. data/rails_generators/rx_config/templates/html-template/history/history.js +645 -0
  67. data/rails_generators/rx_config/templates/html-template/history/historyFrame.html +29 -0
  68. data/rails_generators/rx_config/templates/html-template/index.template.html +121 -0
  69. data/rails_generators/rx_config/templates/html-template/playerProductInstall.swf +0 -0
  70. data/rails_generators/rx_config/templates/index.html.erb +18 -0
  71. data/rails_generators/rx_config/templates/mainair-app.xml +134 -0
  72. data/rails_generators/rx_config/templates/mainapp-config.xml +21 -0
  73. data/rails_generators/rx_config/templates/mainapp.mxml +31 -0
  74. data/rails_generators/rx_config/templates/project-textmate.erb +52 -0
  75. data/rails_generators/rx_config/templates/project.properties +18 -0
  76. data/rails_generators/rx_config/templates/projectair.properties +24 -0
  77. data/rails_generators/rx_config/templates/restfulx.yml +14 -0
  78. data/rails_generators/rx_config/templates/restfulx_tasks.rake +6 -0
  79. data/rails_generators/rx_config/templates/swfobject.js +5 -0
  80. data/rails_generators/rx_controller/USAGE +10 -0
  81. data/rails_generators/rx_controller/rx_controller_generator.rb +28 -0
  82. data/rails_generators/rx_controller/templates/controller.as.erb +40 -0
  83. data/rails_generators/rx_scaffold/USAGE +35 -0
  84. data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +179 -0
  85. data/rails_generators/rx_scaffold/templates/component.mxml.erb +149 -0
  86. data/rails_generators/rx_scaffold/templates/controller.rb.erb +97 -0
  87. data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +35 -0
  88. data/rails_generators/rx_scaffold/templates/migration.rb.erb +19 -0
  89. data/rails_generators/rx_scaffold/templates/model.as.erb +42 -0
  90. data/rails_generators/rx_scaffold/templates/model.rb.erb +11 -0
  91. data/rails_generators/rx_yaml_scaffold/USAGE +51 -0
  92. data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +49 -0
  93. data/rdoc/generators/template/html/jamis.rb +588 -0
  94. data/spec/restfulx_spec.rb +7 -0
  95. data/spec/spec_helper.rb +16 -0
  96. data/tasks/ann.rake +80 -0
  97. data/tasks/bones.rake +20 -0
  98. data/tasks/gem.rake +201 -0
  99. data/tasks/git.rake +40 -0
  100. data/tasks/manifest.rake +48 -0
  101. data/tasks/notes.rake +27 -0
  102. data/tasks/post_load.rake +39 -0
  103. data/tasks/rdoc.rake +50 -0
  104. data/tasks/rubyforge.rake +55 -0
  105. data/tasks/setup.rb +279 -0
  106. data/tasks/spec.rake +54 -0
  107. data/tasks/svn.rake +47 -0
  108. data/tasks/test.rake +40 -0
  109. data/test/rails/controllers/application.rb +15 -0
  110. data/test/rails/controllers/locations_controller.rb +93 -0
  111. data/test/rails/controllers/notes_controller.rb +96 -0
  112. data/test/rails/controllers/projects_controller.rb +93 -0
  113. data/test/rails/controllers/tasks_controller.rb +93 -0
  114. data/test/rails/controllers/users_controller.rb +93 -0
  115. data/test/rails/database.yml +4 -0
  116. data/test/rails/fixtures/locations.yml +8 -0
  117. data/test/rails/fixtures/notes.yml +17 -0
  118. data/test/rails/fixtures/projects.yml +25 -0
  119. data/test/rails/fixtures/simple_properties.yml +19 -0
  120. data/test/rails/fixtures/tasks.yml +46 -0
  121. data/test/rails/fixtures/users.yml +13 -0
  122. data/test/rails/helpers/functional_test_helper.rb +21 -0
  123. data/test/rails/helpers/test_helper.rb +61 -0
  124. data/test/rails/helpers/unit_test_helper.rb +30 -0
  125. data/test/rails/model.yml +35 -0
  126. data/test/rails/models/location.rb +4 -0
  127. data/test/rails/models/note.rb +3 -0
  128. data/test/rails/models/project.rb +4 -0
  129. data/test/rails/models/simple_property.rb +2 -0
  130. data/test/rails/models/task.rb +18 -0
  131. data/test/rails/models/user.rb +20 -0
  132. data/test/rails/playing_around_in_a_console.txt +71 -0
  133. data/test/rails/schema.rb +77 -0
  134. data/test/rails/test.swf +1 -0
  135. data/test/rails/test_active_foo.rb +36 -0
  136. data/test/rails/test_rails_integration_functional.rb +22 -0
  137. data/test/rails/test_to_fxml.rb +35 -0
  138. data/test/rails/test_to_json.rb +23 -0
  139. data/test/rails/views/notes/empty_params_action.html.erb +1 -0
  140. data/test/rails/views/notes/index.html.erb +1 -0
  141. metadata +227 -0
@@ -0,0 +1,93 @@
1
+ class ProjectsController < ApplicationController
2
+ # GET /projects
3
+ # GET /projects.xml
4
+ def index
5
+ @projects = Project.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @projects }
10
+ format.fxml { render :fxml => @projects }
11
+ end
12
+ end
13
+
14
+ # GET /projects/1
15
+ # GET /projects/1.xml
16
+ def show
17
+ @project = Project.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @project }
22
+ format.fxml { render :fxml => @project }
23
+ end
24
+ end
25
+
26
+ # GET /projects/new
27
+ # GET /projects/new.xml
28
+ def new
29
+ @project = Project.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.xml { render :xml => @project }
34
+ format.fxml { render :fxml => @project }
35
+ end
36
+ end
37
+
38
+ # GET /projects/1/edit
39
+ def edit
40
+ @project = Project.find(params[:id])
41
+ end
42
+
43
+ # POST /projects
44
+ # POST /projects.xml
45
+ def create
46
+ @project = Project.new(params[:project])
47
+
48
+ respond_to do |format|
49
+ if @project.save
50
+ flash[:notice] = 'Project was successfully created.'
51
+ format.html { redirect_to(@project) }
52
+ format.xml { render :xml => @project, :status => :created, :location => @project }
53
+ format.fxml { render :fxml => @project }
54
+ else
55
+ format.html { render :action => "new" }
56
+ format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
57
+ format.fxml { render :fxml => @project.errors }
58
+ end
59
+ end
60
+ end
61
+
62
+ # PUT /projects/1
63
+ # PUT /projects/1.xml
64
+ def update
65
+ @project = Project.find(params[:id])
66
+
67
+ respond_to do |format|
68
+ if @project.update_attributes(params[:project])
69
+ flash[:notice] = 'Project was successfully updated.'
70
+ format.html { redirect_to(@project) }
71
+ format.xml { head :ok }
72
+ format.fxml { render :fxml => @project }
73
+ else
74
+ format.html { render :action => "edit" }
75
+ format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
76
+ format.fxml { render :fxml => @project.errors }
77
+ end
78
+ end
79
+ end
80
+
81
+ # DELETE /projects/1
82
+ # DELETE /projects/1.xml
83
+ def destroy
84
+ @project = Project.find(params[:id])
85
+ @project.destroy
86
+
87
+ respond_to do |format|
88
+ format.html { redirect_to(projects_url) }
89
+ format.xml { head :ok }
90
+ format.fxml { render :fxml => @project }
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,93 @@
1
+ class TasksController < ApplicationController
2
+ # GET /tasks
3
+ # GET /tasks.xml
4
+ def index
5
+ @tasks = Task.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @tasks }
10
+ format.fxml { render :fxml => @tasks }
11
+ end
12
+ end
13
+
14
+ # GET /tasks/1
15
+ # GET /tasks/1.xml
16
+ def show
17
+ @task = Task.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @task }
22
+ format.fxml { render :fxml => @task }
23
+ end
24
+ end
25
+
26
+ # GET /tasks/new
27
+ # GET /tasks/new.xml
28
+ def new
29
+ @task = Task.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.xml { render :xml => @task }
34
+ format.fxml { render :fxml => @task }
35
+ end
36
+ end
37
+
38
+ # GET /tasks/1/edit
39
+ def edit
40
+ @task = Task.find(params[:id])
41
+ end
42
+
43
+ # POST /tasks
44
+ # POST /tasks.xml
45
+ def create
46
+ @task = Task.new(params[:task])
47
+
48
+ respond_to do |format|
49
+ if @task.save
50
+ flash[:notice] = 'Task was successfully created.'
51
+ format.html { redirect_to(@task) }
52
+ format.xml { render :xml => @task, :status => :created, :location => @task }
53
+ format.fxml { render :fxml => @task }
54
+ else
55
+ format.html { render :action => "new" }
56
+ format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
57
+ format.fxml { render :fxml => @task.errors }
58
+ end
59
+ end
60
+ end
61
+
62
+ # PUT /tasks/1
63
+ # PUT /tasks/1.xml
64
+ def update
65
+ @task = Task.find(params[:id])
66
+
67
+ respond_to do |format|
68
+ if @task.update_attributes(params[:task])
69
+ flash[:notice] = 'Task was successfully updated.'
70
+ format.html { redirect_to(@task) }
71
+ format.xml { head :ok }
72
+ format.fxml { render :fxml => @task }
73
+ else
74
+ format.html { render :action => "edit" }
75
+ format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
76
+ format.fxml { render :fxml => @task.errors }
77
+ end
78
+ end
79
+ end
80
+
81
+ # DELETE /tasks/1
82
+ # DELETE /tasks/1.xml
83
+ def destroy
84
+ @task = Task.find(params[:id])
85
+ @task.destroy
86
+
87
+ respond_to do |format|
88
+ format.html { redirect_to(tasks_url) }
89
+ format.xml { head :ok }
90
+ format.fxml { render :fxml => @task }
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,93 @@
1
+ class UsersController < ApplicationController
2
+ # GET /users
3
+ # GET /users.xml
4
+ def index
5
+ @users = User.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @users }
10
+ format.fxml { render :fxml => @users }
11
+ end
12
+ end
13
+
14
+ # GET /users/1
15
+ # GET /users/1.xml
16
+ def show
17
+ @user = User.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @user }
22
+ format.fxml { render :fxml => @user }
23
+ end
24
+ end
25
+
26
+ # GET /users/new
27
+ # GET /users/new.xml
28
+ def new
29
+ @user = User.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.xml { render :xml => @user }
34
+ format.fxml { render :fxml => @user }
35
+ end
36
+ end
37
+
38
+ # GET /users/1/edit
39
+ def edit
40
+ @user = User.find(params[:id])
41
+ end
42
+
43
+ # POST /users
44
+ # POST /users.xml
45
+ def create
46
+ @user = User.new(params[:user])
47
+
48
+ respond_to do |format|
49
+ if @user.save
50
+ flash[:notice] = 'User was successfully created.'
51
+ format.html { redirect_to(@user) }
52
+ format.xml { render :xml => @user, :status => :created, :location => @user }
53
+ format.fxml { render :fxml => @user }
54
+ else
55
+ format.html { render :action => "new" }
56
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
57
+ format.fxml { render :fxml => @user.errors }
58
+ end
59
+ end
60
+ end
61
+
62
+ # PUT /users/1
63
+ # PUT /users/1.xml
64
+ def update
65
+ @user = User.find(params[:id])
66
+
67
+ respond_to do |format|
68
+ if @user.update_attributes(params[:user])
69
+ flash[:notice] = 'User was successfully updated.'
70
+ format.html { redirect_to(@user) }
71
+ format.xml { head :ok }
72
+ format.fxml { render :fxml => @user }
73
+ else
74
+ format.html { render :action => "edit" }
75
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
76
+ format.fxml { render :fxml => @user.errors }
77
+ end
78
+ end
79
+ end
80
+
81
+ # DELETE /users/1
82
+ # DELETE /users/1.xml
83
+ def destroy
84
+ @user = User.find(params[:id])
85
+ @user.destroy
86
+
87
+ respond_to do |format|
88
+ format.html { redirect_to(users_url) }
89
+ format.xml { head :ok }
90
+ format.fxml { render :fxml => @user }
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: 'test.sqlite3'
4
+ timeout: 5000
@@ -0,0 +1,8 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ vienna:
3
+ name: Vienna
4
+ user: ludwig
5
+
6
+ stratford:
7
+ name: Stratford Upon Avon
8
+ user: shakespeare
@@ -0,0 +1,17 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
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
@@ -0,0 +1,25 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
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
@@ -0,0 +1,19 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ apple:
4
+ name: Apple
5
+ amount: 12
6
+ price: 10.50
7
+ quantity: 12
8
+ available: true
9
+ delivered_on: <%= 2.days.ago %>
10
+ sold_on: <%= 2.hours.ago %>
11
+
12
+ orange:
13
+ name: Orange
14
+ amount: 15
15
+ price: 15.50
16
+ quantity: 15
17
+ available: false
18
+ delivered_on: <%= 2.days.ago %>
19
+ sold_on: <%= 2.hours.ago %>
@@ -0,0 +1,46 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
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 %>
46
+
@@ -0,0 +1,13 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
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
@@ -0,0 +1,21 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../..')
2
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
3
+ schema_file = File.join(File.dirname(__FILE__), '..', 'schema.rb')
4
+ ENV["RAILS_ENV"] = "test"
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'controllers', 'application')
7
+ require File.join(File.dirname(__FILE__), '..', 'controllers', 'notes_controller')
8
+
9
+ config = YAML::load(IO.read(File.join(File.dirname(__FILE__), '..', 'database.yml')))['test']
10
+ puts "config:\n#{config.inspect}"
11
+ ActiveRecord::Base.configurations = config
12
+ ActiveRecord::Base.establish_connection(config)
13
+
14
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/models.log")
15
+ ActionController::Base.logger = Logger.new(File.dirname(__FILE__) + "/controllers.log")
16
+ ApplicationController.append_view_path File.join(File.dirname(__FILE__), '..', 'views')
17
+
18
+ load(schema_file) if File.exist?(schema_file)
19
+
20
+ Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
21
+ $:.unshift(Test::Unit::TestCase.fixture_path)
@@ -0,0 +1,61 @@
1
+ RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined? RAILS_ROOT
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+
6
+ require 'active_support'
7
+ require 'active_support/test_case'
8
+ require 'active_record'
9
+ require 'active_record/fixtures'
10
+ require 'action_controller'
11
+ require 'action_controller/test_case'
12
+ require 'action_controller/assertions'
13
+ require 'action_controller/test_process'
14
+ require 'action_controller/integration'
15
+ require 'sqlite3'
16
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'restfulx')
17
+ require File.join(File.dirname(__FILE__), '..', 'models', 'note')
18
+ require File.join(File.dirname(__FILE__), '..', 'models', 'user')
19
+ require File.join(File.dirname(__FILE__), '..', 'models', 'project')
20
+ require File.join(File.dirname(__FILE__), '..', 'models', 'location')
21
+ require File.join(File.dirname(__FILE__), '..', 'models', 'task')
22
+ require File.join(File.dirname(__FILE__), '..', 'models', 'simple_property')
23
+
24
+ class MockResponse
25
+ attr_reader :body, :content_type
26
+
27
+ def initialize(body, content_type = 'xml')
28
+ @body = body
29
+ @content_type = content_type
30
+ end
31
+
32
+ end
33
+
34
+ class Test::Unit::TestCase #:nodoc:
35
+ # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
36
+ self.use_transactional_fixtures = true
37
+
38
+ # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
39
+ self.use_instantiated_fixtures = true
40
+
41
+ # Add more helper methods to be used by all tests here...
42
+
43
+ # Use this to test xml or fxml responses in unit tests. For example,
44
+ # set_response_to user.to_fxml
45
+ # assert_xml_select 'user name', 'quentin'
46
+ def set_response_to(response, content_type = 'xml')
47
+ @response = MockResponse.new(response, content_type)
48
+ end
49
+
50
+ # Make xml functional testing work.
51
+ # From http://weblog.jamisbuck.org/2007/1/4/assert_xml_select
52
+ def xml_document
53
+ @xml_document ||= HTML::Document.new(@response.body, false, true)
54
+ end
55
+
56
+ def assert_xml_select(*args, &block)
57
+ @html_document = xml_document
58
+ assert_select(*args, &block)
59
+ end
60
+
61
+ end
@@ -0,0 +1,30 @@
1
+ RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined? RAILS_ROOT
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../..')
4
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
5
+ schema_file = File.join(File.dirname(__FILE__), '..', 'schema.rb')
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/assertions'
17
+ require 'action_controller/test_process'
18
+ require 'action_controller/integration'
19
+ require 'sqlite3'
20
+
21
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'restfulx')
22
+
23
+ config = YAML::load(IO.read(File.join(File.dirname(__FILE__), '..', 'database.yml')))[ENV['DB'] || 'test']
24
+ ActiveRecord::Base.configurations = config
25
+ ActiveRecord::Base.establish_connection(config)
26
+
27
+ load(schema_file) if File.exist?(schema_file)
28
+
29
+ Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
30
+ $:.unshift(Test::Unit::TestCase.fixture_path)
@@ -0,0 +1,35 @@
1
+ project:
2
+ - name: string
3
+ - notes: text
4
+ - start_date: date
5
+ - end_date: date
6
+ - completed: boolean
7
+ - belongs_to: [user]
8
+ - has_many: [tasks]
9
+
10
+ location:
11
+ - name: string
12
+ - notes: text
13
+ - belongs_to: [user]
14
+ - has_many: [tasks]
15
+
16
+ task:
17
+ - name: string
18
+ - notes: text
19
+ - start_time: datetime
20
+ - end_time: datetime
21
+ - completed: boolean
22
+ - next_action: boolean
23
+ - belongs_to: [project, location, user]
24
+
25
+ note:
26
+ - content: text
27
+ - belongs_to: [user]
28
+
29
+ user:
30
+ - login: string
31
+ - first_name: string
32
+ - last_name: string
33
+ - email: string
34
+ - has_many: [tasks, projects, locations]
35
+ - has_one: [note]
@@ -0,0 +1,4 @@
1
+ class Location < ActiveRecord::Base
2
+ belongs_to :user
3
+ has_many :tasks
4
+ end
@@ -0,0 +1,3 @@
1
+ class Note < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,4 @@
1
+ class Project < ActiveRecord::Base
2
+ belongs_to :user
3
+ has_many :tasks
4
+ end
@@ -0,0 +1,2 @@
1
+ class SimpleProperty < ActiveRecord::Base
2
+ end
@@ -0,0 +1,18 @@
1
+ class Task < ActiveRecord::Base
2
+ belongs_to :project
3
+ belongs_to :location
4
+ belongs_to :user
5
+
6
+ def is_active
7
+ case
8
+ when start_time && end_time
9
+ (start_time .. end_time) === Time.now
10
+ when start_time && end_time.nil?
11
+ start_time <= Time.now
12
+ when start_time.nil && end_time
13
+ end_time >= Time.now
14
+ else
15
+ true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ class User < ActiveRecord::Base
2
+ has_one :note
3
+ has_many :tasks
4
+ has_many :projects
5
+ has_many :locations
6
+
7
+ validates_length_of :login, :maximum => 10
8
+
9
+ def full_name
10
+ "#{first_name} #{last_name}"
11
+ end
12
+
13
+ def has_nothing_to_do
14
+ tasks.all? {|task| task.completed}
15
+ end
16
+
17
+ def email_host
18
+ email.split('@').last
19
+ end
20
+ end