house_test 0.1.0 → 0.1.1
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 +5 -5
 - data/.gitlab-ci.yml +12 -0
 - data/.rubocop.yml +1 -1
 - data/Gemfile +2 -0
 - data/Rakefile +2 -0
 - data/bin/console +1 -0
 - data/house_test.gemspec +3 -0
 - data/lib/house_test.rb +4 -0
 - data/lib/house_test/backend/house.rb +3 -1
 - data/lib/house_test/house_server.rb +21 -2
 - data/lib/house_test/indifferent_hash.rb +2 -0
 - data/lib/house_test/server/house_server.rb +7 -5
 - data/lib/house_test/version.rb +3 -1
 - data/rest_client_scripts.rb +5 -2
 - metadata +18 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: aa9b9426fa22a65adf0d6ef9ad20fa4f2bf2a1815453913a0637bba567cbfce8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f65867244ef38f52a91703c31a74637fe2663ee394772a65549884e53c2209a2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5caa100daf29af148492381b98af6ac3aa8264318fe6d538614c5ed181b5c78fee11ab1dab7bc73e12b29f95bb0c4bc8ebc21bbe00c5d383e3fbd5b9c729d17f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ff207e3d24f1adfcaf9c4987c93cbdfdaf5daad056f31ed66e0473d113ca504bc694590f536720dbbf883ef85818872fff09486cc76b7e6dc4dc10e5f70c666c
         
     | 
    
        data/.gitlab-ci.yml
    ADDED
    
    
    
        data/.rubocop.yml
    CHANGED
    
    | 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            Layout/LineLength:
         
     | 
| 
       2 
2 
     | 
    
         
             
              Max: 100
         
     | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    
    
        data/bin/console
    CHANGED
    
    
    
        data/house_test.gemspec
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            lib = File.expand_path('lib', __dir__)
         
     | 
| 
       2 
4 
     | 
    
         
             
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'house_test/version'
         
     | 
| 
         @@ -29,6 +31,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       29 
31 
     | 
    
         
             
              spec.add_development_dependency 'rest-client'
         
     | 
| 
       30 
32 
     | 
    
         
             
              spec.add_development_dependency 'rspec', '~> 3.0'
         
     | 
| 
       31 
33 
     | 
    
         
             
              spec.add_development_dependency 'rubocop'
         
     | 
| 
      
 34 
     | 
    
         
            +
              spec.add_development_dependency 'rubocop-faker'
         
     | 
| 
       32 
35 
     | 
    
         
             
              spec.add_dependency 'faker'
         
     | 
| 
       33 
36 
     | 
    
         
             
              spec.add_dependency 'hashie'
         
     | 
| 
       34 
37 
     | 
    
         
             
              spec.add_dependency 'sinatra', '2.0.4'
         
     | 
    
        data/lib/house_test.rb
    CHANGED
    
    | 
         @@ -1,6 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'faker'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'house_test/version'
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'house_test/indifferent_hash'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'active_support'
         
     | 
| 
      
 7 
     | 
    
         
            +
            ActiveSupport::Deprecation.silenced = true
         
     | 
| 
       4 
8 
     | 
    
         
             
            require 'soaspec'
         
     | 
| 
       5 
9 
     | 
    
         | 
| 
       6 
10 
     | 
    
         
             
            # The code loaded when simply requiring the gem will only load code for the client
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module Backend
         
     | 
| 
       2 
4 
     | 
    
         
             
              # House in memory
         
     | 
| 
       3 
5 
     | 
    
         
             
              class House
         
     | 
| 
         @@ -8,7 +10,7 @@ module Backend 
     | 
|
| 
       8 
10 
     | 
    
         
             
                  params = IndifferentHash.new(house_params)
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
                  self.name = params[:name] || Faker::Name.name
         
     | 
| 
       11 
     | 
    
         
            -
                  self.rooms = (params[:rooms] || Faker::Number.number(1)).to_i
         
     | 
| 
      
 13 
     | 
    
         
            +
                  self.rooms = (params[:rooms] || Faker::Number.number(digits: 1)).to_i
         
     | 
| 
       12 
14 
     | 
    
         
             
                  self.garages = params[:garages] || 1
         
     | 
| 
       13 
15 
     | 
    
         
             
                  self.bathrooms = params[:bathrooms] || rooms - 1
         
     | 
| 
       14 
16 
     | 
    
         
             
                  self.id = SecureRandom.uuid
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'house_test/backend/house'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'house_test/server/house_server'
         
     | 
| 
       3 
5 
     | 
    
         
             
            # Representing House objects in 'backend' (memory)
         
     | 
| 
         @@ -17,20 +19,37 @@ module HouseTest 
     | 
|
| 
       17 
19 
     | 
    
         
             
                end
         
     | 
| 
       18 
20 
     | 
    
         | 
| 
       19 
21 
     | 
    
         
             
                # Get an existing house
         
     | 
| 
      
 22 
     | 
    
         
            +
                # @param [Integer] id Id of house to get
         
     | 
| 
      
 23 
     | 
    
         
            +
                # @return [House] House found. Nil if nothing found
         
     | 
| 
       20 
24 
     | 
    
         
             
                def get(id)
         
     | 
| 
       21 
25 
     | 
    
         
             
                  houses.find { |house| house.id == id }
         
     | 
| 
       22 
26 
     | 
    
         
             
                end
         
     | 
| 
       23 
27 
     | 
    
         | 
| 
       24 
28 
     | 
    
         
             
                # Update house at id's key to value
         
     | 
| 
      
 29 
     | 
    
         
            +
                # @param [Integer] id Id of house to update
         
     | 
| 
      
 30 
     | 
    
         
            +
                # @return [Integer] Id of house updated
         
     | 
| 
       25 
31 
     | 
    
         
             
                def update(id, key, value)
         
     | 
| 
       26 
     | 
    
         
            -
                  found_house =  
     | 
| 
      
 32 
     | 
    
         
            +
                  found_house = get id
         
     | 
| 
      
 33 
     | 
    
         
            +
                  return nil unless found_house
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       27 
35 
     | 
    
         
             
                  found_house.send("#{key}=", value)
         
     | 
| 
       28 
36 
     | 
    
         
             
                  id
         
     | 
| 
       29 
37 
     | 
    
         
             
                end
         
     | 
| 
       30 
38 
     | 
    
         | 
| 
      
 39 
     | 
    
         
            +
                # Delete house at id
         
     | 
| 
      
 40 
     | 
    
         
            +
                # @param [Integer] id Id of house to delete
         
     | 
| 
      
 41 
     | 
    
         
            +
                # @return [Integer] Id of house deleted. Nil if not found
         
     | 
| 
      
 42 
     | 
    
         
            +
                def delete(id)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  found_house = get id
         
     | 
| 
      
 44 
     | 
    
         
            +
                  return nil unless found_house
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  houses.delete(found_house)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  id
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       31 
50 
     | 
    
         
             
                # @return [String] Description of all houses
         
     | 
| 
       32 
51 
     | 
    
         
             
                def descriptions
         
     | 
| 
       33 
52 
     | 
    
         
             
                  houses.map(&:description)
         
     | 
| 
       34 
53 
     | 
    
         
             
                end
         
     | 
| 
       35 
54 
     | 
    
         
             
              end
         
     | 
| 
       36 
     | 
    
         
            -
            end
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'sinatra'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'docdsl'
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'json'
         
     | 
| 
         @@ -37,8 +39,8 @@ class HouseServer < Sinatra::Application 
     | 
|
| 
       37 
39 
     | 
    
         
             
                  query = JSON.parse(request.body.string)
         
     | 
| 
       38 
40 
     | 
    
         
             
                  id = HouseTest.update(id, query.keys.first, query.values.first)
         
     | 
| 
       39 
41 
     | 
    
         
             
                  JSON.generate(updated: id)
         
     | 
| 
       40 
     | 
    
         
            -
                rescue StandardError =>  
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
      
 42 
     | 
    
         
            +
                rescue StandardError => e
         
     | 
| 
      
 43 
     | 
    
         
            +
                  e.message
         
     | 
| 
       42 
44 
     | 
    
         
             
                end
         
     | 
| 
       43 
45 
     | 
    
         
             
              end
         
     | 
| 
       44 
46 
     | 
    
         | 
| 
         @@ -50,8 +52,8 @@ class HouseServer < Sinatra::Application 
     | 
|
| 
       50 
52 
     | 
    
         
             
                             else
         
     | 
| 
       51 
53 
     | 
    
         
             
                               HouseTest.add(JSON.parse(request.body.string))
         
     | 
| 
       52 
54 
     | 
    
         
             
                             end
         
     | 
| 
       53 
     | 
    
         
            -
                rescue StandardError =>  
     | 
| 
       54 
     | 
    
         
            -
                  [200, { 'Content-Type' => 'text/json' },  
     | 
| 
      
 55 
     | 
    
         
            +
                rescue StandardError => e
         
     | 
| 
      
 56 
     | 
    
         
            +
                  [200, { 'Content-Type' => 'text/json' }, e.message]
         
     | 
| 
       55 
57 
     | 
    
         
             
                else
         
     | 
| 
       56 
58 
     | 
    
         
             
                  [200, { 'Content-Type' => 'text/json' }, house_id]
         
     | 
| 
       57 
59 
     | 
    
         
             
                end
         
     | 
| 
         @@ -64,4 +66,4 @@ class HouseServer < Sinatra::Application 
     | 
|
| 
       64 
66 
     | 
    
         
             
              get '/' do
         
     | 
| 
       65 
67 
     | 
    
         
             
                redirect '/docs'
         
     | 
| 
       66 
68 
     | 
    
         
             
              end
         
     | 
| 
       67 
     | 
    
         
            -
            end
         
     | 
| 
      
 69 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/house_test/version.rb
    CHANGED
    
    
    
        data/rest_client_scripts.rb
    CHANGED
    
    | 
         @@ -1,8 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            # Example of using RestClient to create/retrieve houses
         
     | 
| 
       2 
4 
     | 
    
         
             
            # Can open with 'restclient' on cmd line
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'rest_client'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'json'
         
     | 
| 
       4 
7 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            id = RestClient.post('http://localhost: 
     | 
| 
      
 8 
     | 
    
         
            +
            id = RestClient.post('http://localhost:14000/houses', JSON.generate(name: 'test_house')).body
         
     | 
| 
       6 
9 
     | 
    
         
             
            puts id
         
     | 
| 
       7 
10 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            RestClient.get('localhost: 
     | 
| 
      
 11 
     | 
    
         
            +
            RestClient.get('localhost:14000/houses').body
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: house_test
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Samuel Garratt
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-02-07 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -108,6 +108,20 @@ dependencies: 
     | 
|
| 
       108 
108 
     | 
    
         
             
                - - ">="
         
     | 
| 
       109 
109 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       110 
110 
     | 
    
         
             
                    version: '0'
         
     | 
| 
      
 111 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 112 
     | 
    
         
            +
              name: rubocop-faker
         
     | 
| 
      
 113 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 114 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 115 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 116 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 117 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 118 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 119 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 120 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 121 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 122 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 123 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 124 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       111 
125 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       112 
126 
     | 
    
         
             
              name: faker
         
     | 
| 
       113 
127 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -201,6 +215,7 @@ extensions: [] 
     | 
|
| 
       201 
215 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       202 
216 
     | 
    
         
             
            files:
         
     | 
| 
       203 
217 
     | 
    
         
             
            - ".gitignore"
         
     | 
| 
      
 218 
     | 
    
         
            +
            - ".gitlab-ci.yml"
         
     | 
| 
       204 
219 
     | 
    
         
             
            - ".rspec"
         
     | 
| 
       205 
220 
     | 
    
         
             
            - ".rubocop.yml"
         
     | 
| 
       206 
221 
     | 
    
         
             
            - CODE_OF_CONDUCT.md
         
     | 
| 
         @@ -238,8 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       238 
253 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       239 
254 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       240 
255 
     | 
    
         
             
            requirements: []
         
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
            rubygems_version: 2.6.14
         
     | 
| 
      
 256 
     | 
    
         
            +
            rubygems_version: 3.0.6
         
     | 
| 
       243 
257 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       244 
258 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       245 
259 
     | 
    
         
             
            summary: Test system for demonstrating CRUD in API and UI testing.
         
     |