Skip to content

Commit

Permalink
Tests (#68)
Browse files Browse the repository at this point in the history
* Configure AppMap for this project

AppMap is a free and open-source runtime code analysis tool.

AppMap has been installed and configured using the installation instructions at:
https://appmap.io/docs/install-appmap-agent.html using the automated
installer tool:
        npx @appland/appmap@latest install

* Upgrading caxlsx to version 3.4.1

* Upgrading pg to version 1.5.0, view_component to 3.0.0 and parser 3.2.2.1

* Rolling back to appmap 0.98.1

* Fixed the fixtures

* Model: User - Test coverage completed

* Model: Organization - Test implemented

* Adding Test to Events

* Upgrading to appmap 0.99.1

* Removing a test in events_test.rb that would never happened

* Testing the Room model

* Better README

* Upgrading tailwindcss to version 3.3.2

* Upgrading to ruby-openai 4, pg 1.5.2 and i18n 1.13.0

* Working test for Question

* reducing the avatar picture size to 3MB

* Profile tests

* Testing the Vote model

* Testing the Member model

---------

Co-authored-by: Stephane Paquet <spaquet@up4b.com>
  • Loading branch information
spaquet and Stephane Paquet authored Apr 27, 2023
1 parent 0de7fba commit 8c6a9c6
Show file tree
Hide file tree
Showing 34 changed files with 602 additions and 173 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ruby '3.2.2'

# IMPORTANT: This must be the first gem listed
# Add support to appmap in development and test
gem 'appmap', groups: %i[development test]

gem 'appmap', '~> 0.99.1', :groups => [:development, :test]

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 7.0.4'
Expand Down Expand Up @@ -147,7 +148,8 @@ gem 'groupdate'
gem 'chartkick'

# openAI [https://github.com/alexrudall/ruby-openai]
gem "ruby-openai", "~> 3.7.0"
# gem "ruby-openai", "~> 3.7.0"
gem 'ruby-openai', '~> 4.0.0'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
35 changes: 18 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/faker-ruby/faker.git
revision: 6aae8e21e1eaf9ae845017a86c62ae44c9d91654
revision: cfdcdc06e953d05755f2455f4d412cdd71a3dba6
specs:
faker (3.2.0)
i18n (>= 1.8.11, < 2)
Expand Down Expand Up @@ -88,7 +88,7 @@ GEM
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
appmap (0.99.0)
appmap (0.99.1)
activesupport
method_source
rack
Expand All @@ -98,7 +98,7 @@ GEM
ffi-compiler (~> 1.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.750.0)
aws-partitions (1.754.0)
aws-sdk-core (3.171.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -130,7 +130,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
caxlsx (3.4.0)
caxlsx (3.4.1)
htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
Expand Down Expand Up @@ -161,6 +161,8 @@ GEM
faraday (2.7.4)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.0.2)
ffi (1.15.5)
ffi-compiler (1.0.1)
Expand All @@ -181,10 +183,7 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.12.0)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
Expand Down Expand Up @@ -224,6 +223,7 @@ GEM
minitest (5.18.0)
msgpack (1.7.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
net-imap (0.3.4)
date
net-protocol
Expand Down Expand Up @@ -268,16 +268,16 @@ GEM
activerecord (>= 6.0)
request_store (~> 1.4)
parallel (1.23.0)
parser (3.2.2.0)
parser (3.2.2.1)
ast (~> 2.4.1)
pg (1.4.6)
pg (1.5.2)
public_suffix (5.0.1)
puma (6.2.2)
nio4r (~> 2.0)
pundit (2.3.0)
activesupport (>= 3.0.0)
racc (1.6.2)
rack (2.2.6.4)
rack (2.2.7)
rack-protection (3.0.6)
rack
rack-test (2.1.0)
Expand Down Expand Up @@ -343,8 +343,9 @@ GEM
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-openai (3.7.0)
httparty (>= 0.18.1)
ruby-openai (4.0.0)
faraday (>= 1)
faraday-multipart (>= 1)
ruby-progressbar (1.13.0)
ruby-vips (2.1.4)
ffi (~> 1.12)
Expand All @@ -353,7 +354,7 @@ GEM
rubyzip (2.3.2)
safely_block (0.3.0)
errbase (>= 0.1.1)
selenium-webdriver (4.8.6)
selenium-webdriver (4.9.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down Expand Up @@ -397,7 +398,7 @@ GEM
activemodel (>= 3.0.0)
public_suffix
version_gem (1.1.2)
view_component (2.82.0)
view_component (3.0.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
Expand Down Expand Up @@ -428,7 +429,7 @@ DEPENDENCIES
active_storage_validations (~> 1.0.0)
ahoy_matey
annotate (~> 3.2.0)
appmap
appmap (~> 0.99.1)
argon2 (~> 2.2.0)
aws-sdk-s3
bootsnap
Expand Down Expand Up @@ -466,7 +467,7 @@ DEPENDENCIES
rqrcode (~> 2.0)
rubocop (~> 1.50)
rubocop-rails
ruby-openai (~> 3.7.0)
ruby-openai (~> 4.0.0)
ruby-vips (>= 2.1.0)
selenium-webdriver
sendgrid-actionmailer (~> 3.2.0)
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ Using openAI, THEPEW provides personalized recommendations that are tailored to
## LICENSE
[License](../master/LICENSE.md)

## INSTALLATION
### PREREQUISITES
- ruby (version 3.2 with YJIT)
- rails (version 7.0.4)
- postgresql (version 14 or above)
- mailcatcher
- redis (version 6.2)
- docker (used by postgres, redis and mailcatcher)

### INSTALLING POSTGRES USING DOCKER
docker run -p 5432:5432 --name postgres-15.2-alpine -e POSTGRES_PASSWORD=mysecretpassword -d postgres:15.2-alpine

### INSTALLING REDIS USING DOCKER
docker run -p 6379:6379 --name redis-6.2-alpine -d 6.2-alpine

### INSTALLING MAILCATCHER USING DOCKER
docker run -p 1080:1080 -p 1025:1025 --name mailcatcher -d stpaquet/alpinemailcatcher

For more information you can read this medium post [https://medium.com/@spaquet/mailcatcher-to-the-rescue-4ba438dc98c2](https://medium.com/@spaquet/mailcatcher-to-the-rescue-4ba438dc98c2)

## CREDITS
5 changes: 4 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class Event < ApplicationRecord

private

# Note: If the way end_date is defined in the set_values method changes,
# make sure to implement a corresponding test to check if the validation
# for end_date being before start_date is working correctly.
def set_values
self.end_date = start_date
self.short_code = generate_pin if self.short_code.nil?
Expand All @@ -92,7 +95,7 @@ def generate_qr_code
end

def set_duration
self.duration = (end_date - start_date).to_i
self.duration = (end_date - start_date).to_i if start_date.present? && end_date.present?
end

def end_date_is_after_start_date
Expand Down
2 changes: 1 addition & 1 deletion app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Profile < ApplicationRecord

validates :nickname, presence: true, length: { minimum: 3, maximum: 40 }
validates :avatar, content_type: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
size: { between: 1.kilobyte..5.megabytes, message: 'is not given between size' }
size: { between: 1.kilobyte..3.megabytes, message: 'is not given between size' }

enum mode: { light: 0, dark: 1 }
end
4 changes: 3 additions & 1 deletion app/models/vote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def voted(choice)
up_vote? ? cancel! : up_vote!
when 'down_vote'
down_vote? ? cancel! : down_vote!
when 'cancel'
cancel!
else
logger.error "User #{self.user_id} tried to use an invalid vote choice: #{choice}"
errors.add(:choice, 'invalid_choice')
return
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/credentials/test.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mquKD5SQ1ZTO/QEpuzkDbCovd5Ccyajt3qx2AMUP76b9E/MjdvHXwamvU/mCx/r8AGfLAbgFxDI6K76fxlUxAMZQvzYV3CAelh1n5BoJSGdiDnb19gZG3kkM4TT7LcDbTd4ih//XfDpZOlEh5PRK2is1JMCMFK+eXbWBP9+mY/KtOlCdly2vpkc31wMpv0nLp6pNEcdXPXGG4567NwJ16FAS9FlyHJo13Nj/Ij1QdxODgblX2cLHRrOUgI8Hv6n/bysTvzB+Sc1gHWwV0JhH8CqeKlJL4N9lEyMVeZib8nUk8mtr--AkvKnFlBEtqtNyzE--AE0SuYCOwsD5hrxi/8mVdQ==
5NJN3Y6KMkCetxaHyWcfPCMi+645pJ5L0x8i1tbGkHll9KXwytRIyNta2+GRp28wqB1YSaZVw3PozaxPXnRXoBMSqXwGJ9uMa8wd/bOLMjD7xshLxc30XI8WeGsqWWhFdJUfuU7sYU9P45cGDNWm8gmmLqgp32lR3EmigzKbmPotIQIQOE4jKsxyaA3p/CcEHtknIziz3Fvn6L/J46FWwtQHTCWWHnSsuJxUHwV/kN6O1/4SlS1iKoQkp4DDf3/fLZIAuY2uh3Qg45oat769V7ui0FanEMUG4X7VIrfmuKhxzjhfRoDuvmD67KfbGen7jVvVQfWZGcQIjXTxP4KO2pFqsCoSenmS4OmjxBvr5xZFRNEbuSpTUaGLQgodj0r0jWvqnfs9GLI8k6mi8n3XkpQ9YaUBOT6y+8qTZAyw1HbLSl8xl0VUR2pqRARqlB6E1tR4etGtQG6I2qHj/s1qLHbL0A==--14YPOo/2EgX5UY3T--nRK2OHJcEiVrVmLePW2iBw==
4 changes: 2 additions & 2 deletions test/fixtures/active_sessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
#

one:
user: one
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0
ip_address: 192.168.1.1
remember_token: KbiDE4Lze1TkoCx1ek1nGaU6

two:
user: two
user_id: 60322e8a-5b0a-4d1b-8e69-9accea00e1a0
user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0
ip_address: 192.168.1.2
remember_token: TN23ZBEzJDTu6wUUHyjBnLkh
2 changes: 1 addition & 1 deletion test/fixtures/attendances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#

one:
user: one
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
event: one
room_id: 1
start_time: <%= DateTime.now.utc %>
10 changes: 5 additions & 5 deletions test/fixtures/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ one:
end_date: <%= Time.current.utc + 1.day %>
duration: 1
short_code: 123456
user: one
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
event_type: universal
status: opened
organization_id: organizations(one).id
organization_id: 8c5e36bb-6163-4d07-8a7e-9f13e77d6e40

two:
name: Event with an invalid stop date
start_date: <%= Time.current.utc + 1.day %>
end_date: <%= Time.current.utc - 2.day %>
end_date: <%= Time.current.utc - 2.days %>
duration: 1
short_code: nil
user: one
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
event_type: universal
status: archived
organization_id: organizations(one).id
organization_id: 8c5e36bb-6163-4d07-8a7e-9f13e77d6e40
Binary file added test/fixtures/files/large-avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/files/test-avatar.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/files/test-avatar.pdf
Binary file not shown.
14 changes: 8 additions & 6 deletions test/fixtures/import_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#

one:
user: one
status: MyString
message: MyText
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
status: :success
filename: "success_file.xlsx"


two:
user: two
status: MyString
message: MyText
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
status: :error
message: "An error occured while uploading the file"
filename: "error_file.xls"
12 changes: 6 additions & 6 deletions test/fixtures/members.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
# index_members_on_user_id (user_id)
#

one:
user: one
organization: one
john:
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
organization_id: 8c5e36bb-6163-4d07-8a7e-9f13e77d6e40
owner: true

two:
user: two
organization: two
jane:
user_id: 60322e8a-5b0a-4d1b-8e69-9accea00e1a0
organization_id: 8c5e36bb-6163-4d07-8a7e-9f13e77d6e40
owner: false
4 changes: 2 additions & 2 deletions test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

one:
content: MyText
user: one
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39

two:
content: MyText
user: two
user_id: 60322e8a-5b0a-4d1b-8e69-9accea00e1a0
4 changes: 3 additions & 1 deletion test/fixtures/organizations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
#

one:
id: 8c5e36bb-6163-4d07-8a7e-9f13e77d6e40
name: ACME Inc
website: https://www.acme.com
country:
domain: acme.com
domain_verified: true
domain_verified_at: <%= Time.current.utc %>
dns_txt: sOmeRandomeString
dns_txt: sOmeRandomeStringWithEnoughCharactersToMakeIt126InTotalABCDEFGHIJ0123456789KLMNOPQRSTUVWXYZabcdefghijklmno1234567890abcdefghjk

two:
id: 8c2e36bb-1963-4d07-8a7d-9f13e77d6e19
name: Supa Corp
website: https://supa.corp.com
country:
16 changes: 12 additions & 4 deletions test/fixtures/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@
#

one:
user: one
nickname: User1 NickaName
user_id: 7c5e36bb-6163-4d07-8e7e-9f13e77d6e39
nickname: Johny

two:
user: two
nickname: User2 Simple
user_id: 60322e8a-5b0a-4d1b-8e69-9accea00e1a0
nickname: Jane

three:
user_id: 60355e8a-5b0a-4d1b-8e69-9accea00e10a
nickname: Joe

four:
user_id: 60322e8a-5b0a-4d3b-8e70-9accea00e10b
nickname: Mary
Loading

0 comments on commit 8c6a9c6

Please sign in to comment.