moviepilot-restful 0.2.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGES.markdown +40 -0
  2. data/LICENSE.markdown +22 -0
  3. data/README.markdown +126 -0
  4. data/Rakefile +22 -0
  5. data/TODO.markdown +10 -0
  6. data/init.rb +1 -0
  7. data/lib/restful/apimodel/attribute.rb +17 -0
  8. data/lib/restful/apimodel/collection.rb +22 -0
  9. data/lib/restful/apimodel/link.rb +21 -0
  10. data/lib/restful/apimodel/map.rb +41 -0
  11. data/lib/restful/apimodel/resource.rb +23 -0
  12. data/lib/restful/converters/active_record.rb +159 -0
  13. data/lib/restful/rails/action_controller.rb +14 -0
  14. data/lib/restful/rails/active_record/configuration.rb +219 -0
  15. data/lib/restful/rails/active_record/metadata_tools.rb +102 -0
  16. data/lib/restful/rails.rb +22 -0
  17. data/lib/restful/serializers/atom_like_serializer.rb +51 -0
  18. data/lib/restful/serializers/base.rb +58 -0
  19. data/lib/restful/serializers/hash_serializer.rb +46 -0
  20. data/lib/restful/serializers/json_serializer.rb +18 -0
  21. data/lib/restful/serializers/params_serializer.rb +46 -0
  22. data/lib/restful/serializers/xml_serializer.rb +161 -0
  23. data/lib/restful.rb +65 -0
  24. data/rails/init.rb +1 -0
  25. data/restful.gemspec +17 -0
  26. data/test/converters/active_record_converter_test.rb +147 -0
  27. data/test/converters/basic_types_converter_test.rb +99 -0
  28. data/test/fixtures/models/paginated_collection.rb +3 -0
  29. data/test/fixtures/models/person.rb +29 -0
  30. data/test/fixtures/models/pet.rb +5 -0
  31. data/test/fixtures/models/wallet.rb +5 -0
  32. data/test/fixtures/people.json.yaml +107 -0
  33. data/test/fixtures/people.xml.yaml +117 -0
  34. data/test/fixtures/pets.json.yaml +20 -0
  35. data/test/fixtures/pets.xml.yaml +31 -0
  36. data/test/rails/active_record_metadata_test.rb +23 -0
  37. data/test/rails/configuration_test.rb +47 -0
  38. data/test/rails/restful_publish_test.rb +54 -0
  39. data/test/serializers/atom_serializer_test.rb +33 -0
  40. data/test/serializers/json_serializer_test.rb +90 -0
  41. data/test/serializers/params_serializer_test.rb +76 -0
  42. data/test/serializers/xml_serializer_test.rb +51 -0
  43. data/test/test_helper.rb +154 -0
  44. metadata +97 -0
@@ -0,0 +1,154 @@
1
+ require 'rubygems'
2
+ require 'ruby-debug'
3
+ require 'active_support'
4
+ require 'active_record'
5
+ require 'action_controller'
6
+ require 'test/spec'
7
+ require 'mocha'
8
+ require 'hpricot'
9
+ require 'xmlsimple'
10
+ require 'yajl'
11
+ require 'pathname'
12
+ require 'stringio'
13
+
14
+ plugin_test = Pathname.new(File.dirname(__FILE__))
15
+ plugin_root = plugin_test.join '..'
16
+ plugin_lib = plugin_root.join 'lib'
17
+
18
+ $:.unshift plugin_lib, plugin_test
19
+
20
+ RAILS_ENV = "test"
21
+ RAILS_ROOT = plugin_root # fake the rails root directory.
22
+ RESTFUL_ROOT = plugin_root
23
+
24
+ ActiveRecord::Base.logger = Logger.new(STDERR)
25
+ ActiveRecord::Base.logger.level = Logger::ERROR
26
+ ActiveRecord::Base.colorize_logging = false
27
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
28
+
29
+ silence_stream(STDOUT) do
30
+ ActiveRecord::Schema.define do
31
+
32
+ create_table :pets do |t|
33
+ t.integer :age, :default => 10
34
+ t.string :name
35
+ t.integer :species
36
+ t.integer :person_id
37
+ t.string :type
38
+
39
+ t.timestamps
40
+ end
41
+
42
+ create_table :houses do |t|
43
+ t.string :name
44
+
45
+ t.timestamps
46
+ end
47
+
48
+ create_table :people do |t|
49
+ t.string :name
50
+ t.string :current_location
51
+ t.string :biography
52
+ t.integer :house_id
53
+ t.date :birthday
54
+ t.datetime :last_login
55
+
56
+ t.timestamps
57
+ end
58
+
59
+ create_table :wallets do |t|
60
+ t.string :person_id
61
+ t.string :contents
62
+
63
+ t.timestamps
64
+ end
65
+ end
66
+ end
67
+
68
+ require plugin_root.join 'init'
69
+ require 'fixtures/models/house'
70
+ require 'fixtures/models/pet'
71
+ require 'fixtures/models/emu'
72
+ require 'fixtures/models/wallet'
73
+ require 'fixtures/models/person'
74
+ require 'fixtures/models/paginated_collection'
75
+
76
+ Restful::Rails.api_hostname = "http://example.com:3000"
77
+
78
+ #
79
+ # Helper methods
80
+ #
81
+ def reset_config
82
+ Person.restful_config = Restful.cfg
83
+ Pet.restful_config = Restful.cfg
84
+ Wallet.restful_config = Restful.cfg
85
+ end
86
+
87
+ def xml_cmp(actual, expected)
88
+ eq_all_but_zero = Object.new.instance_eval do
89
+ def ==(other)
90
+ Integer(other) == 0 ? false : true
91
+ end
92
+ self
93
+ end
94
+
95
+ actual = XmlSimple.xml_in(actual.to_s, 'normalisespace' => eq_all_but_zero)
96
+ expected = XmlSimple.xml_in(expected.to_s, 'normalisespace' => eq_all_but_zero)
97
+ actual == expected
98
+ end
99
+
100
+ def json_cmp(actual, expected)
101
+ actual = Yajl::Parser.parse(actual)
102
+ expected = Yajl::Parser.parse(expected)
103
+ puts_hash_diff actual, expected
104
+ actual == expected
105
+ end
106
+
107
+ def puts_hash_diff(hash1, hash2, indent = 0)
108
+ return if hash1 == hash2
109
+
110
+ ((hash1 || {}).keys + (hash2 || {}).keys).uniq.each do |key|
111
+ next if hash1[key] == hash2[key]
112
+ print " "*indent
113
+ if hash1[key].is_a? Hash or hash2[key].is_a? Hash
114
+ puts "=== #{key} is a Hash ==="
115
+ puts_hash_diff(hash1[key] || {}, hash2[key] || {}, indent+2)
116
+ else
117
+ printf "%-#{20-indent}s %#{50-indent}s != %-50s\n", key[0..19], hash1[key], hash2[key]
118
+ end
119
+ end
120
+ end
121
+
122
+ def xml_should_eql_fixture(actual, name, key)
123
+ expected = Hpricot(xml_fixture(name)[key])
124
+ actual = Hpricot(actual)
125
+
126
+ xml_should_eql(actual, expected)
127
+ end
128
+
129
+ # doing this tests that the content is the same regardless of attribute order etc.
130
+ def xml_should_eql(actual, expected)
131
+ same = xml_cmp(actual, expected)
132
+ actual.should.== expected unless same
133
+ end
134
+
135
+ def json_should_eql_fixture(actual, name, key)
136
+ expected = json_fixture(name)[key]
137
+ json_should_eql(actual, expected)
138
+ end
139
+
140
+ # doing this tests that the content is the same regardless of attribute order etc.
141
+ def json_should_eql(actual, expected)
142
+ same = json_cmp(actual, expected)
143
+ actual.should.== expected unless same
144
+ end
145
+
146
+ def file_fixture(name)
147
+ template = File.open(RESTFUL_ROOT.join("test", "fixtures", name)).read
148
+ fixture = ERB.new(template).result(binding)
149
+ yaml = YAML.load(fixture)
150
+ yaml.symbolize_keys
151
+ end
152
+
153
+ def xml_fixture(name); file_fixture("#{ name }.xml.yaml"); end
154
+ def json_fixture(name); file_fixture("#{ name }.json.yaml"); end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moviepilot-restful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.18
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Bornkessel
8
+ - Rany Keddo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-08-11 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: M4SSIVE@m4ssive.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.markdown
25
+ files:
26
+ - CHANGES.markdown
27
+ - init.rb
28
+ - lib/restful/apimodel/attribute.rb
29
+ - lib/restful/apimodel/collection.rb
30
+ - lib/restful/apimodel/link.rb
31
+ - lib/restful/apimodel/map.rb
32
+ - lib/restful/apimodel/resource.rb
33
+ - lib/restful/converters/active_record.rb
34
+ - lib/restful/rails/action_controller.rb
35
+ - lib/restful/rails/active_record/configuration.rb
36
+ - lib/restful/rails/active_record/metadata_tools.rb
37
+ - lib/restful/rails.rb
38
+ - lib/restful/serializers/atom_like_serializer.rb
39
+ - lib/restful/serializers/base.rb
40
+ - lib/restful/serializers/hash_serializer.rb
41
+ - lib/restful/serializers/json_serializer.rb
42
+ - lib/restful/serializers/params_serializer.rb
43
+ - lib/restful/serializers/xml_serializer.rb
44
+ - lib/restful.rb
45
+ - LICENSE.markdown
46
+ - rails/init.rb
47
+ - Rakefile
48
+ - README.markdown
49
+ - restful.gemspec
50
+ - test/converters/active_record_converter_test.rb
51
+ - test/converters/basic_types_converter_test.rb
52
+ - test/fixtures/models/paginated_collection.rb
53
+ - test/fixtures/models/person.rb
54
+ - test/fixtures/models/pet.rb
55
+ - test/fixtures/models/wallet.rb
56
+ - test/fixtures/people.json.yaml
57
+ - test/fixtures/people.xml.yaml
58
+ - test/fixtures/pets.json.yaml
59
+ - test/fixtures/pets.xml.yaml
60
+ - test/rails/active_record_metadata_test.rb
61
+ - test/rails/configuration_test.rb
62
+ - test/rails/restful_publish_test.rb
63
+ - test/serializers/atom_serializer_test.rb
64
+ - test/serializers/json_serializer_test.rb
65
+ - test/serializers/params_serializer_test.rb
66
+ - test/serializers/xml_serializer_test.rb
67
+ - test/test_helper.rb
68
+ - TODO.markdown
69
+ has_rdoc: true
70
+ homepage: http://github.com/M4SSIVE/restful
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --line-numbers
74
+ - --inline-source
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements:
90
+ - brianmario-yajl-ruby
91
+ rubyforge_project:
92
+ rubygems_version: 1.2.0
93
+ signing_key:
94
+ specification_version: 2
95
+ summary: api niceness.
96
+ test_files: []
97
+