Skip to content

Commit

Permalink
merge testing to add tests to staging branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Jet committed May 3, 2021
2 parents c257770 + 44b8e1f commit d9ec8ea
Show file tree
Hide file tree
Showing 33 changed files with 437 additions and 98 deletions.
53 changes: 53 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Documentation here https://circleci.com/developer/orbs/orb/later/ruby-rails-setup
# Following tutorial https://thoughtbot.com/blog/circleci-2-rails

version: 2.1
orbs:
ruby: circleci/ruby@0.1.2
ruby-rails-setup: later/ruby-rails-setup@0.0.3

jobs:
build:
working_directory: ~/compost-lyon
docker:
- image: circleci/ruby:2.6.3-node-browsers
environment:
PGHOST: localhost
PGUSER: CompostLyon
RAILS_ENV: test
RACK_ENV: test
NODE_ENV: test
- image: postgres:9.5
environment:
POSTGRES_USER: CompostLyon
POSTGRES_DB: CompostLyon_test
POSTGRES_PASSWORD: <%= ENV['COMPOSTLYON_DATABASE_PASSWORD'] %>
executor: ruby/default
steps:
- checkout
- run:
name: Configure Bundler
command: |
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
source $BASH_ENV
gem install bundler
# Bundle install dependencies
- run: bundle install
- run: yarn install
- run: bin/rails webpacker:compile
- save_cache:
key: v1-bundle-{{ checksum "Gemfile.lock" }}-{{ checksum "yarn.lock" }}
paths:
- vendor/bundle
- public/packs-test
# Setup the database
- run: bundle exec rake db:drop RAILS_ENV=test
- run: bundle exec rake db:create RAILS_ENV=test
- run: bundle exec rake db:schema:load RAILS_ENV=test

# --- RSPEC

- run:
name: Running tests
command: bundle exec rspec
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :development, :test do
gem 'rspec-rails', '~> 5.0.0'
gem "factory_bot_rails"
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
gem 'minitest-around'
gem 'database_cleaner-active_record'
end

Expand Down
34 changes: 25 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.4.4)
dotenv (2.7.6)
dotenv-rails (2.7.6)
dotenv (= 2.7.6)
Expand All @@ -111,6 +112,11 @@ GEM
request_store (>= 1.0)
erubi (1.10.0)
execjs (2.7.0)
factory_bot (6.1.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.1.0)
factory_bot (~> 6.1.0)
railties (>= 5.0.0)
faraday (1.4.1)
faraday-excon (~> 1.1)
faraday-net_http (~> 1.0)
Expand Down Expand Up @@ -161,7 +167,6 @@ GEM
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
libv8-node (15.14.0.1)
libv8-node (15.14.0.1-x86_64-linux)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -174,19 +179,13 @@ GEM
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.0.3)
mini_portile2 (2.5.1)
mini_racer (0.4.0)
libv8-node (~> 15.14.0.0)
minitest (5.14.4)
minitest-around (0.5.0)
minitest (~> 5.0)
msgpack (1.4.2)
multipart-post (2.1.1)
nested_form (0.3.2)
nio4r (2.5.7)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
nokogiri (1.11.3-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
Expand Down Expand Up @@ -266,6 +265,23 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (5.0.1)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
ruby2_keywords (0.0.4)
rubyzip (2.3.0)
sass-rails (6.0.0)
Expand Down Expand Up @@ -342,7 +358,6 @@ GEM
zeitwerk (2.4.2)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand All @@ -356,14 +371,14 @@ DEPENDENCIES
devise
dotenv-rails
draper
factory_bot_rails
font-awesome-sass
friendly_id
geocoder
jbuilder (~> 2.7)
letter_opener_web
listen (>= 3.0.5, < 3.2)
mini_racer
minitest-around
pg (>= 0.18, < 2.0)
pry-byebug
pry-rails
Expand All @@ -374,6 +389,7 @@ DEPENDENCIES
rails_admin-i18n
redis (~> 4.0)
rexml (~> 3.2, >= 3.2.5)
rspec-rails (~> 5.0.0)
sass-rails (>= 6)
selenium-webdriver
sentry-rails
Expand Down
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module ApplicationHelper

# Translations in config/locales/fr.yml
def action_path_name(action)
I18n.t("resources.#{action}")
end

# Translations in config/locales/pages_data/content.yml
def page_path_name(page)
I18n.t("pages.#{page}.path_name")
end
Expand Down
2 changes: 2 additions & 0 deletions app/services/exception_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ExceptionLogger
def self.send(exception, options = {})
if Rails.env.production?
Sentry.capture_exception(exception, extra: options)
elsif Rails.env.test?
puts exception.to_yaml
else
msg = exception.try(:message) || exception.to_s
Rails.logger.info "Sending exception to Sentry : #{msg} ;"
Expand Down
2 changes: 1 addition & 1 deletion app/services/site_name_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class SiteNameFormatter
def self.format(name)
format_name = name.gsub(/(?:le|les)\s?compost?(\w)+/i, 'Composteur')
format_name = name.gsub(/(?:le|les)?\s?compost?(\w)+/i, 'Composteur')
format_name.prepend('Composteur ') unless format_name.split.first == 'Composteur'
format_name.strip
end
Expand Down
5 changes: 5 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

config.assets.configure do |env|
env.export_concurrent = false
end


# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true
end
4 changes: 4 additions & 0 deletions spec/factories/collective_composting_organisation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryBot.define do
factory :organisation, class: CollectiveComposting::Organisation do
end
end
6 changes: 6 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :user do
firstname { "John" }
lastname { "Doe" }
end
end
17 changes: 17 additions & 0 deletions spec/features/visitor_signs_in_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# spec/features/visitor_signs_up_spec.rb
require 'rails_helper'

feature 'User signs in' do
scenario 'successfuly with correct password' do
sign_in_existing_user_with_correct_password
expect(page).to have_content('Deconnexion')
end
scenario 'with wrong password gets error message' do
sign_in_existing_user_with_wrong_password
expect(page).to have_content('Courriel ou mot de passe incorrect')
end
scenario 'with wrong email gets error message' do
sign_in_existing_user_with_wrong_email
expect(page).to have_content('Courriel ou mot de passe incorrect')
end
end
22 changes: 22 additions & 0 deletions spec/features/visitor_signs_up_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# spec/features/visitor_signs_up_spec.rb
require 'rails_helper'

feature 'Visitor signs up' do
scenario 'with valid email and password' do
sign_up_with 'valid@example.com', 'password'

expect(page).to have_content('Deconnexion')
end

scenario 'with invalid email' do
sign_up_with 'invalid_email', 'password'

expect(page).to have_content('Me connecter')
end

scenario 'with blank password' do
sign_up_with 'valid@example.com', ''

expect(page).to have_content('Me connecter')
end
end
28 changes: 28 additions & 0 deletions spec/features/visitor_visits_main_pages_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rails_helper'

feature 'Visitor visits' do
scenario 'home page' do
visit root_path
expect(page).to have_title('Compost Lyon - tout sur le compost à Lyon')
end
scenario 'about page' do
visit about_path
expect(page).to have_title('Compost Lyon - Le projet')
end
scenario 'collective composting page' do
visit collective_composting_path
expect(page).to have_title('Compostage collectif à Lyon')
end
scenario 'sites index' do
visit sites_path
expect(page).to have_title('Composteurs collectifs de quartier de Lyon et des environs')
end
scenario 'condominium sites index' do
visit condominium_sites_path
expect(page).to have_title('Composteurs collectifs de copropriété à Lyon')
end
scenario 'organisations index' do
visit collective_composting_organisations_path
expect(page).to have_title('Compostage collectif - les acteurs')
end
end
39 changes: 39 additions & 0 deletions spec/models/site_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'rails_helper'
RSpec.describe Site, :type => :model do
context "name changes" do

before(:all) do
user = create(:user, email: 'testing@gmail.com', password: 'password')
@organisation = create(:organisation, name: 'Collectif test', user_id: user.id)
end

describe "name is 'Compost Bahadourian (de la Guill)'" do
it "slug is 'composteur-bahadourian-de-la-guill'" do
site = @organisation.sites.create(name: "Compost Bahadourian (de la Guill)")
expect(site.formatted_name).to eq("Composteur Bahadourian (de la Guill)")
expect(site.slug).to eq("composteur-bahadourian-de-la-guill")
end
end
describe "name is 'Compostage Potakin'" do
it "slug is 'composteur-potakin'" do
site = @organisation.sites.create(name: "Compostage Potakin")
expect(site.formatted_name).to eq("Composteur Potakin")
expect(site.slug).to eq("composteur-potakin")
end
end
describe "name is 'Composteur ATOME Village'" do
it "slug is 'composteur-atome-village'" do
site = @organisation.sites.create(name: "Composteur ATOME Village")
expect(site.formatted_name).to eq("Composteur ATOME Village")
expect(site.slug).to eq("composteur-atome-village")
end
end
describe "name is 'Clos de Fourvière'" do
it "slug is 'composteur-clos-de-fourviere'" do
site = @organisation.sites.create(name: "Clos de Fourvière")
expect(site.formatted_name).to eq("Composteur Clos de Fourvière")
expect(site.slug).to eq("composteur-clos-de-fourviere")
end
end
end
end
Loading

0 comments on commit d9ec8ea

Please sign in to comment.