restful_objects 0.0.2 → 0.0.3
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.
- checksums.yaml +8 -8
- data/README.md +3 -2
- data/bin/restful_server.rb +0 -0
- data/lib/restful_objects/action_description.rb +96 -82
- data/lib/restful_objects/action_list.rb +17 -17
- data/lib/restful_objects/collection_description.rb +47 -47
- data/lib/restful_objects/collection_list.rb +17 -17
- data/lib/restful_objects/domain_model.rb +83 -79
- data/lib/restful_objects/http_response.rb +11 -11
- data/lib/restful_objects/link_generator.rb +104 -104
- data/lib/restful_objects/object.rb +20 -20
- data/lib/restful_objects/object_actions.rb +134 -134
- data/lib/restful_objects/object_base.rb +10 -0
- data/lib/restful_objects/object_collections.rb +84 -84
- data/lib/restful_objects/object_list.rb +16 -16
- data/lib/restful_objects/object_macros.rb +35 -35
- data/lib/restful_objects/object_properties.rb +78 -78
- data/lib/restful_objects/parameter_description.rb +60 -60
- data/lib/restful_objects/parameter_description_list.rb +15 -15
- data/lib/restful_objects/property_description.rb +68 -68
- data/lib/restful_objects/property_list.rb +17 -17
- data/lib/restful_objects/service.rb +21 -21
- data/lib/restful_objects/service_list.rb +55 -55
- data/lib/restful_objects/type.rb +110 -110
- data/lib/restful_objects/type_list.rb +30 -30
- data/lib/restful_objects/user.rb +30 -30
- data/lib/restful_objects/version.rb +1 -1
- data/spec/integration/domain-types_actions_spec.rb +43 -43
- data/spec/integration/domain-types_collections_spec.rb +45 -45
- data/spec/integration/domain-types_properties_spec.rb +41 -41
- data/spec/integration/server-root_spec.rb +98 -98
- data/spec/spec_helper.rb +52 -52
- data/spec/unit/object_actions_spec.rb +380 -380
- data/spec/unit/object_collections_spec.rb +190 -190
- data/spec/unit/object_properties_spec.rb +215 -206
- data/spec/unit/object_spec.rb +228 -228
- data/spec/unit/service_spec.rb +125 -125
- data/spec/unit/type_list_spec.rb +37 -37
- metadata +2 -2
    
        data/lib/restful_objects/type.rb
    CHANGED
    
    | @@ -1,110 +1,110 @@ | |
| 1 | 
            -
            module RestfulObjects
         | 
| 2 | 
            -
              class Type
         | 
| 3 | 
            -
                include LinkGenerator
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                attr_reader :id, :is_service, :properties, :collections, :actions
         | 
| 6 | 
            -
                attr_accessor :friendly_name, :plural_name, :description
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def initialize(id)
         | 
| 9 | 
            -
                  @id = id
         | 
| 10 | 
            -
                  @properties = PropertyList.new(id)
         | 
| 11 | 
            -
                  @collections = CollectionList.new(id)
         | 
| 12 | 
            -
                  @actions = ActionList.new(id)
         | 
| 13 | 
            -
                  @is_service = false
         | 
| 14 | 
            -
                  @friendly_name = ''
         | 
| 15 | 
            -
                  @plural_name = ''
         | 
| 16 | 
            -
                  @description = ''
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def get_representation
         | 
| 20 | 
            -
                  { 'name' => @id,
         | 
| 21 | 
            -
                    'domainType' => @id,
         | 
| 22 | 
            -
                    'friendlyName' => @friendly_name,
         | 
| 23 | 
            -
                    'pluralName' => @plural_name,
         | 
| 24 | 
            -
                    'description' => @description,
         | 
| 25 | 
            -
                    'isService' => @is_service,
         | 
| 26 | 
            -
                    'members' => get_members,
         | 
| 27 | 
            -
                    'typeActions' => get_type_actions,
         | 
| 28 | 
            -
                    'links' => [ link_to(:self, "/domain-types/#{@id}", :domain_type) ],
         | 
| 29 | 
            -
                    'extensions' => {}
         | 
| 30 | 
            -
                  }.to_json
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def new_proto_persistent_object
         | 
| 34 | 
            -
                  persist_link = link_to(:persist, "/objects/#{id}", :object, method: 'POST')
         | 
| 35 | 
            -
                  persist_link['arguments'] = { 'members' => {} }
         | 
| 36 | 
            -
                  members = {}
         | 
| 37 | 
            -
                  properties.each do |name, property|
         | 
| 38 | 
            -
                    if not property.optional
         | 
| 39 | 
            -
                      persist_link['arguments']['members'][name] = {
         | 
| 40 | 
            -
                        'value' => nil,
         | 
| 41 | 
            -
                        'extensions' => property.metadata }
         | 
| 42 | 
            -
                    end
         | 
| 43 | 
            -
                    members[name] = { 'value' => nil }
         | 
| 44 | 
            -
                  end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  { 'title' => "New #{id}",
         | 
| 47 | 
            -
                    'members' => members,
         | 
| 48 | 
            -
                    'links' => [ persist_link ],
         | 
| 49 | 
            -
                    'extensions' => {} }
         | 
| 50 | 
            -
                end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                def post_prototype_object(members_json)
         | 
| 53 | 
            -
                  members = JSON.parse(members_json)['members']
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                  new_object = Object.const_get(@id.to_sym).new
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                  members.each do |name, value|
         | 
| 58 | 
            -
                    if properties.include?(name) then
         | 
| 59 | 
            -
                      new_object.put_property_as_json(name, value.to_json)
         | 
| 60 | 
            -
                    else
         | 
| 61 | 
            -
                      raise "member of property '#{name}' not found in type '#{@id}'"
         | 
| 62 | 
            -
                    end
         | 
| 63 | 
            -
                  end
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                  new_object.get_representation
         | 
| 66 | 
            -
                end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                def metadata
         | 
| 69 | 
            -
                  { 'domainType' => id,
         | 
| 70 | 
            -
                    'friendlyName' => friendly_name,
         | 
| 71 | 
            -
                    'pluralName' => plural_name,
         | 
| 72 | 
            -
                    'description' => description,
         | 
| 73 | 
            -
                    'isService' => is_service }
         | 
| 74 | 
            -
                end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                private
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                  def get_members
         | 
| 79 | 
            -
                    properties_members.merge(collections_members.merge(actions_members))
         | 
| 80 | 
            -
                  end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                  def properties_members
         | 
| 83 | 
            -
                    result = Hash.new
         | 
| 84 | 
            -
                    @properties.each do |name, property|
         | 
| 85 | 
            -
                      result[name] = link_to(:property, "/domain-types/#{@id}/properties/#{name}", :property_description)
         | 
| 86 | 
            -
                    end
         | 
| 87 | 
            -
                    result
         | 
| 88 | 
            -
                  end
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                  def collections_members
         | 
| 91 | 
            -
                    result = Hash.new
         | 
| 92 | 
            -
                    @collections.each do |name, collection|
         | 
| 93 | 
            -
                      result[name] = link_to(:collection, "/domain-types/#{@id}/collections/#{name}", :collection_description)
         | 
| 94 | 
            -
                    end
         | 
| 95 | 
            -
                    result
         | 
| 96 | 
            -
                  end
         | 
| 97 | 
            -
             | 
| 98 | 
            -
                  def actions_members
         | 
| 99 | 
            -
                    result = Hash.new
         | 
| 100 | 
            -
                    @actions.each do |name, action|
         | 
| 101 | 
            -
                      result[name] = link_to(:action, "/domain-types/#{@id}/actions/#{name}", :action_description)
         | 
| 102 | 
            -
                    end
         | 
| 103 | 
            -
                    result
         | 
| 104 | 
            -
                  end
         | 
| 105 | 
            -
             | 
| 106 | 
            -
                  def get_type_actions
         | 
| 107 | 
            -
                    {}
         | 
| 108 | 
            -
                  end
         | 
| 109 | 
            -
              end
         | 
| 110 | 
            -
            end
         | 
| 1 | 
            +
            module RestfulObjects
         | 
| 2 | 
            +
              class Type
         | 
| 3 | 
            +
                include LinkGenerator
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                attr_reader :id, :is_service, :properties, :collections, :actions
         | 
| 6 | 
            +
                attr_accessor :friendly_name, :plural_name, :description
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(id)
         | 
| 9 | 
            +
                  @id = id
         | 
| 10 | 
            +
                  @properties = PropertyList.new(id)
         | 
| 11 | 
            +
                  @collections = CollectionList.new(id)
         | 
| 12 | 
            +
                  @actions = ActionList.new(id)
         | 
| 13 | 
            +
                  @is_service = false
         | 
| 14 | 
            +
                  @friendly_name = ''
         | 
| 15 | 
            +
                  @plural_name = ''
         | 
| 16 | 
            +
                  @description = ''
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def get_representation
         | 
| 20 | 
            +
                  { 'name' => @id,
         | 
| 21 | 
            +
                    'domainType' => @id,
         | 
| 22 | 
            +
                    'friendlyName' => @friendly_name,
         | 
| 23 | 
            +
                    'pluralName' => @plural_name,
         | 
| 24 | 
            +
                    'description' => @description,
         | 
| 25 | 
            +
                    'isService' => @is_service,
         | 
| 26 | 
            +
                    'members' => get_members,
         | 
| 27 | 
            +
                    'typeActions' => get_type_actions,
         | 
| 28 | 
            +
                    'links' => [ link_to(:self, "/domain-types/#{@id}", :domain_type) ],
         | 
| 29 | 
            +
                    'extensions' => {}
         | 
| 30 | 
            +
                  }.to_json
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def new_proto_persistent_object
         | 
| 34 | 
            +
                  persist_link = link_to(:persist, "/objects/#{id}", :object, method: 'POST')
         | 
| 35 | 
            +
                  persist_link['arguments'] = { 'members' => {} }
         | 
| 36 | 
            +
                  members = {}
         | 
| 37 | 
            +
                  properties.each do |name, property|
         | 
| 38 | 
            +
                    if not property.optional
         | 
| 39 | 
            +
                      persist_link['arguments']['members'][name] = {
         | 
| 40 | 
            +
                        'value' => nil,
         | 
| 41 | 
            +
                        'extensions' => property.metadata }
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
                    members[name] = { 'value' => nil }
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  { 'title' => "New #{id}",
         | 
| 47 | 
            +
                    'members' => members,
         | 
| 48 | 
            +
                    'links' => [ persist_link ],
         | 
| 49 | 
            +
                    'extensions' => {} }
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def post_prototype_object(members_json)
         | 
| 53 | 
            +
                  members = JSON.parse(members_json)['members']
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  new_object = Object.const_get(@id.to_sym).new
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  members.each do |name, value|
         | 
| 58 | 
            +
                    if properties.include?(name) then
         | 
| 59 | 
            +
                      new_object.put_property_as_json(name, value.to_json)
         | 
| 60 | 
            +
                    else
         | 
| 61 | 
            +
                      raise "member of property '#{name}' not found in type '#{@id}'"
         | 
| 62 | 
            +
                    end
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  new_object.get_representation
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                def metadata
         | 
| 69 | 
            +
                  { 'domainType' => id,
         | 
| 70 | 
            +
                    'friendlyName' => friendly_name,
         | 
| 71 | 
            +
                    'pluralName' => plural_name,
         | 
| 72 | 
            +
                    'description' => description,
         | 
| 73 | 
            +
                    'isService' => is_service }
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                private
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  def get_members
         | 
| 79 | 
            +
                    properties_members.merge(collections_members.merge(actions_members))
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  def properties_members
         | 
| 83 | 
            +
                    result = Hash.new
         | 
| 84 | 
            +
                    @properties.each do |name, property|
         | 
| 85 | 
            +
                      result[name] = link_to(:property, "/domain-types/#{@id}/properties/#{name}", :property_description)
         | 
| 86 | 
            +
                    end
         | 
| 87 | 
            +
                    result
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                  def collections_members
         | 
| 91 | 
            +
                    result = Hash.new
         | 
| 92 | 
            +
                    @collections.each do |name, collection|
         | 
| 93 | 
            +
                      result[name] = link_to(:collection, "/domain-types/#{@id}/collections/#{name}", :collection_description)
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
                    result
         | 
| 96 | 
            +
                  end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                  def actions_members
         | 
| 99 | 
            +
                    result = Hash.new
         | 
| 100 | 
            +
                    @actions.each do |name, action|
         | 
| 101 | 
            +
                      result[name] = link_to(:action, "/domain-types/#{@id}/actions/#{name}", :action_description)
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
                    result
         | 
| 104 | 
            +
                  end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                  def get_type_actions
         | 
| 107 | 
            +
                    {}
         | 
| 108 | 
            +
                  end
         | 
| 109 | 
            +
              end
         | 
| 110 | 
            +
            end
         | 
| @@ -1,30 +1,30 @@ | |
| 1 | 
            -
            module RestfulObjects
         | 
| 2 | 
            -
              class TypeList
         | 
| 3 | 
            -
                extend Forwardable
         | 
| 4 | 
            -
                include LinkGenerator
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                def initialize
         | 
| 7 | 
            -
                  @types = Hash.new
         | 
| 8 | 
            -
                end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                def add(name)
         | 
| 11 | 
            -
                  @types[name] = Type.new(name)
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                def get_representation
         | 
| 15 | 
            -
                  response =  {
         | 
| 16 | 
            -
                   'links' => [
         | 
| 17 | 
            -
                      link_to(:self, '/domain-types', :type_list),
         | 
| 18 | 
            -
                      link_to(:up, '/', :homepage),
         | 
| 19 | 
            -
                    ],
         | 
| 20 | 
            -
                    'value' => []
         | 
| 21 | 
            -
                  }
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  each { |name, type| response['value'] << link_to(:domain_type, "/domain-types/#{name}", :domain_type) }
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  response.to_json
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                def_delegators :@types, :[], :each, :include?, :size?, :clear, :empty?
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         | 
| 1 | 
            +
            module RestfulObjects
         | 
| 2 | 
            +
              class TypeList
         | 
| 3 | 
            +
                extend Forwardable
         | 
| 4 | 
            +
                include LinkGenerator
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize
         | 
| 7 | 
            +
                  @types = Hash.new
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def add(name)
         | 
| 11 | 
            +
                  @types[name] = Type.new(name)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def get_representation
         | 
| 15 | 
            +
                  response =  {
         | 
| 16 | 
            +
                   'links' => [
         | 
| 17 | 
            +
                      link_to(:self, '/domain-types', :type_list),
         | 
| 18 | 
            +
                      link_to(:up, '/', :homepage),
         | 
| 19 | 
            +
                    ],
         | 
| 20 | 
            +
                    'value' => []
         | 
| 21 | 
            +
                  }
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  each { |name, type| response['value'] << link_to(:domain_type, "/domain-types/#{name}", :domain_type) }
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  response.to_json
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def_delegators :@types, :[], :each, :include?, :size?, :clear, :empty?
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
    
        data/lib/restful_objects/user.rb
    CHANGED
    
    | @@ -1,30 +1,30 @@ | |
| 1 | 
            -
            module RestfulObjects
         | 
| 2 | 
            -
              class User
         | 
| 3 | 
            -
                include LinkGenerator
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                attr_reader :base_url, :user_name
         | 
| 6 | 
            -
                attr_accessor :friendly_name, :email
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def initialize(base_url, user_name)
         | 
| 9 | 
            -
                  @base_url = base_url
         | 
| 10 | 
            -
                  @user_name = user_name
         | 
| 11 | 
            -
                  @friendly_name = ''
         | 
| 12 | 
            -
                  @email = ''
         | 
| 13 | 
            -
                  @roles = Array.new
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                def add_role(role)
         | 
| 17 | 
            -
                  @roles.push(role)
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def get_as_json
         | 
| 21 | 
            -
                  { 'links' => [ gen_link('self', '/user', 'user'), gen_link('up', '/', 'homepage') ],
         | 
| 22 | 
            -
                    'userName' => @user_name,
         | 
| 23 | 
            -
                    'friendlyName' => @friendly_name,
         | 
| 24 | 
            -
                    'email' => @email,
         | 
| 25 | 
            -
                    'roles' => @roles,
         | 
| 26 | 
            -
                    'extensions' => {}
         | 
| 27 | 
            -
                  }.to_json
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         | 
| 1 | 
            +
            module RestfulObjects
         | 
| 2 | 
            +
              class User
         | 
| 3 | 
            +
                include LinkGenerator
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                attr_reader :base_url, :user_name
         | 
| 6 | 
            +
                attr_accessor :friendly_name, :email
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(base_url, user_name)
         | 
| 9 | 
            +
                  @base_url = base_url
         | 
| 10 | 
            +
                  @user_name = user_name
         | 
| 11 | 
            +
                  @friendly_name = ''
         | 
| 12 | 
            +
                  @email = ''
         | 
| 13 | 
            +
                  @roles = Array.new
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def add_role(role)
         | 
| 17 | 
            +
                  @roles.push(role)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def get_as_json
         | 
| 21 | 
            +
                  { 'links' => [ gen_link('self', '/user', 'user'), gen_link('up', '/', 'homepage') ],
         | 
| 22 | 
            +
                    'userName' => @user_name,
         | 
| 23 | 
            +
                    'friendlyName' => @friendly_name,
         | 
| 24 | 
            +
                    'email' => @email,
         | 
| 25 | 
            +
                    'roles' => @roles,
         | 
| 26 | 
            +
                    'extensions' => {}
         | 
| 27 | 
            +
                  }.to_json
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| @@ -1,43 +1,43 @@ | |
| 1 | 
            -
            # encoding: utf-8
         | 
| 2 | 
            -
            require_relative '../spec_helper'
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            describe '/domain-types/:type/actions/:action' do
         | 
| 5 | 
            -
              before(:all) do
         | 
| 6 | 
            -
                RestfulObjects::DomainModel.current.reset
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              it 'should generate an action description representation' do
         | 
| 10 | 
            -
                class ActionTest
         | 
| 11 | 
            -
                  include RestfulObjects::Object
         | 
| 12 | 
            -
                  action :do_something, :int,  | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                expected = {
         | 
| 16 | 
            -
                  'id' => 'do_something',
         | 
| 17 | 
            -
                  'friendlyName' => 'do something!',
         | 
| 18 | 
            -
                  'description' => 'description of something',
         | 
| 19 | 
            -
                  'hasParams' => false,
         | 
| 20 | 
            -
                  'memberOrder' => :integer,
         | 
| 21 | 
            -
                  'parameters' => {},
         | 
| 22 | 
            -
                  'links' => [
         | 
| 23 | 
            -
                    { 'rel' => 'self',
         | 
| 24 | 
            -
                      'href' => 'http://localhost/domain-types/ActionTest/actions/do_something',
         | 
| 25 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-description"',
         | 
| 26 | 
            -
                      'method' => 'GET' },
         | 
| 27 | 
            -
                    { 'rel' => 'up',
         | 
| 28 | 
            -
                      'href' => 'http://localhost/domain-types/ActionTest',
         | 
| 29 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 30 | 
            -
                      'method' => 'GET' },
         | 
| 31 | 
            -
                    { 'rel' => 'urn:org.restfulobjects:rels/return-type',
         | 
| 32 | 
            -
                      'href' => 'http://localhost/domain-types/int',
         | 
| 33 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 34 | 
            -
                      'method' => 'GET' }
         | 
| 35 | 
            -
                  ]
         | 
| 36 | 
            -
                }
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                get '/domain-types/ActionTest/actions/do_something'
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                last_response.body.should match_json_expression expected
         | 
| 41 | 
            -
              end
         | 
| 42 | 
            -
            end
         | 
| 43 | 
            -
             | 
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require_relative '../spec_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe '/domain-types/:type/actions/:action' do
         | 
| 5 | 
            +
              before(:all) do
         | 
| 6 | 
            +
                RestfulObjects::DomainModel.current.reset
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it 'should generate an action description representation' do
         | 
| 10 | 
            +
                class ActionTest
         | 
| 11 | 
            +
                  include RestfulObjects::Object
         | 
| 12 | 
            +
                  action :do_something, return_type: :int, friendly_name: 'do something!', description: 'description of something'
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                expected = {
         | 
| 16 | 
            +
                  'id' => 'do_something',
         | 
| 17 | 
            +
                  'friendlyName' => 'do something!',
         | 
| 18 | 
            +
                  'description' => 'description of something',
         | 
| 19 | 
            +
                  'hasParams' => false,
         | 
| 20 | 
            +
                  'memberOrder' => :integer,
         | 
| 21 | 
            +
                  'parameters' => {},
         | 
| 22 | 
            +
                  'links' => [
         | 
| 23 | 
            +
                    { 'rel' => 'self',
         | 
| 24 | 
            +
                      'href' => 'http://localhost/domain-types/ActionTest/actions/do_something',
         | 
| 25 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/action-description"',
         | 
| 26 | 
            +
                      'method' => 'GET' },
         | 
| 27 | 
            +
                    { 'rel' => 'up',
         | 
| 28 | 
            +
                      'href' => 'http://localhost/domain-types/ActionTest',
         | 
| 29 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 30 | 
            +
                      'method' => 'GET' },
         | 
| 31 | 
            +
                    { 'rel' => 'urn:org.restfulobjects:rels/return-type',
         | 
| 32 | 
            +
                      'href' => 'http://localhost/domain-types/int',
         | 
| 33 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 34 | 
            +
                      'method' => 'GET' }
         | 
| 35 | 
            +
                  ]
         | 
| 36 | 
            +
                }
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                get '/domain-types/ActionTest/actions/do_something'
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                last_response.body.should match_json_expression expected
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
| 43 | 
            +
             | 
| @@ -1,45 +1,45 @@ | |
| 1 | 
            -
            # encoding: utf-8
         | 
| 2 | 
            -
            require_relative '../spec_helper'
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            describe '/domain-types/:type/collections/:collection' do
         | 
| 5 | 
            -
              before(:all) do
         | 
| 6 | 
            -
                RestfulObjects::DomainModel.current.reset
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              it 'should generate a collection description representation' do
         | 
| 10 | 
            -
                class CollectionTest
         | 
| 11 | 
            -
                  include RestfulObjects::Object
         | 
| 12 | 
            -
                  collection :items, 'ItemClass', friendly_name: 'item collection', description: 'a collection description'
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                expected = {
         | 
| 16 | 
            -
                  'id' => 'items',
         | 
| 17 | 
            -
                  'friendlyName' => 'item collection',
         | 
| 18 | 
            -
                  'description' => 'a collection description',
         | 
| 19 | 
            -
                  'memberOrder' => 1,
         | 
| 20 | 
            -
                  'links' => [
         | 
| 21 | 
            -
                    { 'rel' => 'self',
         | 
| 22 | 
            -
                      'href' => 'http://localhost/domain-types/CollectionTest/collections/items',
         | 
| 23 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/collection-description"',
         | 
| 24 | 
            -
                      'method' => 'GET' },
         | 
| 25 | 
            -
                    { 'rel' => 'up',
         | 
| 26 | 
            -
                      'href' => 'http://localhost/domain-types/CollectionTest',
         | 
| 27 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 28 | 
            -
                      'method' => 'GET' },
         | 
| 29 | 
            -
                    { 'rel' => 'urn:org.restfulobjects:rels/return-type',
         | 
| 30 | 
            -
                      'href' => 'http://localhost/domain-types/list',
         | 
| 31 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 32 | 
            -
                      'method' => 'GET' },
         | 
| 33 | 
            -
                    { 'rel' => 'urn:org.restfulobjects:rels/element-type',
         | 
| 34 | 
            -
                      'href' => 'http://localhost/domain-types/ItemClass',
         | 
| 35 | 
            -
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 36 | 
            -
                      'method' => 'GET' }
         | 
| 37 | 
            -
                  ],
         | 
| 38 | 
            -
                  'extensions' => wildcard_matcher
         | 
| 39 | 
            -
                }
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                get '/domain-types/CollectionTest/collections/items'
         | 
| 42 | 
            -
                last_response.body.should match_json_expression expected
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
            end
         | 
| 45 | 
            -
             | 
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require_relative '../spec_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe '/domain-types/:type/collections/:collection' do
         | 
| 5 | 
            +
              before(:all) do
         | 
| 6 | 
            +
                RestfulObjects::DomainModel.current.reset
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it 'should generate a collection description representation' do
         | 
| 10 | 
            +
                class CollectionTest
         | 
| 11 | 
            +
                  include RestfulObjects::Object
         | 
| 12 | 
            +
                  collection :items, 'ItemClass', friendly_name: 'item collection', description: 'a collection description'
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                expected = {
         | 
| 16 | 
            +
                  'id' => 'items',
         | 
| 17 | 
            +
                  'friendlyName' => 'item collection',
         | 
| 18 | 
            +
                  'description' => 'a collection description',
         | 
| 19 | 
            +
                  'memberOrder' => 1,
         | 
| 20 | 
            +
                  'links' => [
         | 
| 21 | 
            +
                    { 'rel' => 'self',
         | 
| 22 | 
            +
                      'href' => 'http://localhost/domain-types/CollectionTest/collections/items',
         | 
| 23 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/collection-description"',
         | 
| 24 | 
            +
                      'method' => 'GET' },
         | 
| 25 | 
            +
                    { 'rel' => 'up',
         | 
| 26 | 
            +
                      'href' => 'http://localhost/domain-types/CollectionTest',
         | 
| 27 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 28 | 
            +
                      'method' => 'GET' },
         | 
| 29 | 
            +
                    { 'rel' => 'urn:org.restfulobjects:rels/return-type',
         | 
| 30 | 
            +
                      'href' => 'http://localhost/domain-types/list',
         | 
| 31 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 32 | 
            +
                      'method' => 'GET' },
         | 
| 33 | 
            +
                    { 'rel' => 'urn:org.restfulobjects:rels/element-type',
         | 
| 34 | 
            +
                      'href' => 'http://localhost/domain-types/ItemClass',
         | 
| 35 | 
            +
                      'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
         | 
| 36 | 
            +
                      'method' => 'GET' }
         | 
| 37 | 
            +
                  ],
         | 
| 38 | 
            +
                  'extensions' => wildcard_matcher
         | 
| 39 | 
            +
                }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                get '/domain-types/CollectionTest/collections/items'
         | 
| 42 | 
            +
                last_response.body.should match_json_expression expected
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
| 45 | 
            +
             |