house_test 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 30f86898a56ca3a25fdf51b7aa3f2b5a023792a0
4
- data.tar.gz: 8a22d9dea25927a632cebbd40a522c320628b659
2
+ SHA256:
3
+ metadata.gz: aa9b9426fa22a65adf0d6ef9ad20fa4f2bf2a1815453913a0637bba567cbfce8
4
+ data.tar.gz: f65867244ef38f52a91703c31a74637fe2663ee394772a65549884e53c2209a2
5
5
  SHA512:
6
- metadata.gz: af33c1e1e9b9c003a25d76d0a0876b5f70e1a2df89898225bda1ff7a0aaa4a579a63e2c624604f0e27ccd11794b4728b1607086e6dc79344f4b87d4b69e31023
7
- data.tar.gz: 792727d92470a5dad57181edf48c591a2edebc63102453f0744cb83f8fee90eaf267307ccba06a0cfce28f593aaa6fd9b9260a4b7cc2c407ccc672c2e448a675
6
+ metadata.gz: 5caa100daf29af148492381b98af6ac3aa8264318fe6d538614c5ed181b5c78fee11ab1dab7bc73e12b29f95bb0c4bc8ebc21bbe00c5d383e3fbd5b9c729d17f
7
+ data.tar.gz: ff207e3d24f1adfcaf9c4987c93cbdfdaf5daad056f31ed66e0473d113ca504bc694590f536720dbbf883ef85818872fff09486cc76b7e6dc4dc10e5f70c666c
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,12 @@
1
+ image: ruby:2.6
2
+
3
+ before_script:
4
+ - ruby -v
5
+ - which ruby
6
+ - gem install bundler rake
7
+ - bundle install
8
+
9
+ test:
10
+ stage: test
11
+ script:
12
+ - bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,2 +1,2 @@
1
- Metrics/LineLength:
1
+ Layout/LineLength:
2
2
  Max: 100
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'house_test'
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 = houses.find { |house| house.id == id }
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 'hashie'
2
4
 
3
5
  # Hash that allows accessing hash with either string or Hash
@@ -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 => exception
41
- exception.message
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 => exception
54
- [200, { 'Content-Type' => 'text/json' }, exception.message]
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HouseTest
2
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.1.1'
3
5
  end
@@ -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:4567/houses', JSON.generate(name: 'test_house')).body
8
+ id = RestClient.post('http://localhost:14000/houses', JSON.generate(name: 'test_house')).body
6
9
  puts id
7
10
 
8
- RestClient.get('localhost:4567/houses').body
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.0
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: 2019-02-10 00:00:00.000000000 Z
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
- rubyforge_project:
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.