diff --git a/Rakefile b/Rakefile old mode 100755 new mode 100644 index 1015d36a8..baff55158 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path("config/application", __dir__) +require File.expand_path('../config/application', __FILE__) Rails.application.load_tasks diff --git a/config.ru b/config.ru index 441e6ff0c..f7ba0b527 100644 --- a/config.ru +++ b/config.ru @@ -1,5 +1,5 @@ # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application diff --git a/config/application.rb b/config/application.rb index 2b95c2b73..b98b2311a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,6 +1,6 @@ -require File.expand_path("boot", __dir__) +require File.expand_path('../boot', __FILE__) -require "rails/all" +require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -13,11 +13,11 @@ class Application < Rails::Application # I18n configuration config.i18n.default_locale = :es - config.i18n.available_locales = %i[es ca eu gl en pt-BR fr] + config.i18n.available_locales = [:es, :ca, :eu, :gl, :en, :'pt-BR', :fr] config.i18n.fallbacks = true # This tells Rails to serve error pages from the app itself, rather than using static error pages in public/ - config.exceptions_app = routes + config.exceptions_app = self.routes # Activate the Skylight agent in staging. You need to provision the # SKYLIGHT_AUTHENTICATION env var for this to work. @@ -31,10 +31,10 @@ class Application < Rails::Application config.active_record.schema_format = :sql # Guard against DNS rebinding attacks by permitting hosts - config.hosts << "localhost" - config.hosts << "timeoverflow.local" - config.hosts << "staging.timeoverflow.org" - config.hosts << "www.timeoverflow.org" - config.hosts << "timeoverflow.org" + config.hosts << 'localhost' + config.hosts << 'timeoverflow.local' + config.hosts << 'staging.timeoverflow.org' + config.hosts << 'www.timeoverflow.org' + config.hosts << 'timeoverflow.org' end end diff --git a/config/boot.rb b/config/boot.rb index 988a5ddc4..b9e460cef 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require "bundler/setup" # Set up gems listed in the Gemfile. -require "bootsnap/setup" # Speed up boot time by caching expensive operations. +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/environment.rb b/config/environment.rb index cac531577..426333bb4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 55817c081..000e5f03b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,13 +14,13 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp/caching-dev.txt").exist? + if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -38,7 +38,7 @@ config.action_mailer.delivery_method = :letter_opener config.action_mailer.default_url_options = { - host: ENV["MAIL_LINK_HOST"] || "localhost:3000" + host: (ENV["MAIL_LINK_HOST"] || "localhost:3000") } # Print deprecation notices to the Rails logger. diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 221c983cc..cb080f68a 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,2 +1,2 @@ -# Use same settings we use for production +# Use same settings we use for production require_relative "production" diff --git a/config/environments/test.rb b/config/environments/test.rb index e7efdf9fd..a897f877b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -16,7 +16,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/config/routes.rb b/config/routes.rb index f5002e932..500c4581d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,11 @@ -require "sidekiq/web" -require "sidekiq/cron/web" +require 'sidekiq/web' +require 'sidekiq/cron/web' Rails.application.routes.draw do root to: "home#index" authenticate :user, lambda { |u| Rails.env.development? || u.superadmin? } do - mount Sidekiq::Web => "/sidekiq" + mount Sidekiq::Web => '/sidekiq' end devise_for :users, controllers: { sessions: "sessions" } @@ -16,7 +16,7 @@ ActiveAdmin.routes(self) - get :switch_lang, to: "application#switch_lang" + get :switch_lang, to: 'application#switch_lang' get "/pages/:page" => "pages#show", as: :page @@ -28,35 +28,34 @@ get :give_time, on: :member end - resources :organizations, except: %i[new create destroy], concerns: :accountable do + resources :organizations, except: [:new, :create, :destroy], concerns: :accountable do member do post :set_current end end - get :select_organization, to: "organizations#select_organization" + get :select_organization, to: 'organizations#select_organization' - resources :users, concerns: :accountable, except: :destroy, path: "members" do + resources :users, concerns: :accountable, except: :destroy, :path => "members" do collection do - get "signup" - get "manage" - get "please_confirm" + get 'signup' + get 'manage' + get 'please_confirm' end end - put :update_avatar, to: "users#update_avatar" + put :update_avatar, to: 'users#update_avatar' - resources :petitions, only: %i[create update] do + resources :petitions, only: [:create, :update] do collection do - get "manage" + get 'manage' end end - resources :transfers, only: %i[new create] do + resources :transfers, only: [:new, :create] do member do put :delete_reason end end - match "multi/step/:step", to: "multi_transfers#step", via: %i[get post], - as: :multi_transfers_step + match "multi/step/:step", to: "multi_transfers#step", via: [:get, :post], as: :multi_transfers_step post "multi/create", to: "multi_transfers#create", as: :multi_transfers_create resources :documents @@ -100,6 +99,6 @@ end end - match "/404", to: "errors#not_found", via: :all - match "/500", to: "errors#internal_server_error", via: :all + match '/404', to: 'errors#not_found', via: :all + match '/500', to: 'errors#internal_server_error', via: :all end diff --git a/spec/admin/organizations_controller_spec.rb b/spec/admin/organizations_controller_spec.rb index 18218fc90..cf0f77f2e 100644 --- a/spec/admin/organizations_controller_spec.rb +++ b/spec/admin/organizations_controller_spec.rb @@ -12,12 +12,10 @@ it "sign out if current user is logged to organization deleted" do session[:current_organization_id] = organization.id - expect do + expect { delete :destroy, params: { id: organization.id } - end.to change { controller.current_user }.to(nil). - and change { - session[:current_organization_id] - }.to(nil) + }.to change { controller.current_user }.to(nil) + .and change { session[:current_organization_id] }.to(nil) end end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index c8a96495f..ade414f43 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -1,5 +1,5 @@ RSpec.describe ApplicationController do - describe "#switch_lang" do + describe '#switch_lang' do let(:original_locale) { I18n.locale } before do @@ -10,7 +10,7 @@ I18n.locale = original_locale end - it "switches locale to passed language via params" do + it 'switches locale to passed language via params' do new_locale = (I18n.available_locales - [original_locale]).sample expect do diff --git a/spec/controllers/device_tokens_controller_spec.rb b/spec/controllers/device_tokens_controller_spec.rb index c8ae67d76..f97c6d62a 100644 --- a/spec/controllers/device_tokens_controller_spec.rb +++ b/spec/controllers/device_tokens_controller_spec.rb @@ -2,27 +2,27 @@ let (:organization) { Fabricate(:organization) } let (:member) { Fabricate(:member, organization: organization) } - describe "POST #create" do - context "without login" do - it "responds with error" do + describe 'POST #create' do + context 'without login' do + it 'responds with error' do expect do post :create end.to change(DeviceToken, :count).by(0) end end - context "with valid params" do - it "creates a new device_token" do + context 'with valid params' do + it 'creates a new device_token' do login(member.user) expect do - post :create, params: { token: "xxx" } + post :create, params: { token: 'xxx' } end.to change(DeviceToken, :count).by(1) end end - context "with invalid params" do - it "responds with error" do + context 'with invalid params' do + it 'responds with error' do login(member.user) post :create expect(response.status).to eq(422) diff --git a/spec/controllers/inquiries_controller_spec.rb b/spec/controllers/inquiries_controller_spec.rb index 0a443d210..0a78b1982 100644 --- a/spec/controllers/inquiries_controller_spec.rb +++ b/spec/controllers/inquiries_controller_spec.rb @@ -42,8 +42,8 @@ expect do post "create", params: { inquiry: { user: another_member.user, - category_id: test_category.id, - title: "New title" } } + category_id: test_category.id, + title: "New title" }} end.to change(Inquiry, :count).by(1) end end diff --git a/spec/controllers/multi_transfers_controller_spec.rb b/spec/controllers/multi_transfers_controller_spec.rb index 2817c759e..1d243a0e7 100644 --- a/spec/controllers/multi_transfers_controller_spec.rb +++ b/spec/controllers/multi_transfers_controller_spec.rb @@ -12,7 +12,7 @@ category: test_category) end - it "creates one to many transfers" do + it 'creates one to many transfers' do expect do login(admin.user) @@ -37,14 +37,14 @@ post :step, params: params.merge!( step: 5, - transfer: { amount: 3600, reason: "because of reasons" } + transfer: {amount: 3600, reason: 'because of reasons'} ) post :create, params: params end.to change { Transfer.count }.by(2) end - it "creates many to one transfers" do + it 'creates many to one transfers' do expect do login(admin.user) @@ -69,15 +69,15 @@ post :step, params: params.merge!( step: 5, - transfer: { amount: 3600, reason: "because of reasons" } + transfer: {amount: 3600, reason: 'because of reasons'} ) post :create, params: params end.to change { Transfer.count }.by(2) end - context "when only one source and one target is selected" do - it "creates one to one transfers" do + context 'when only one source and one target is selected' do + it 'creates one to one transfers' do expect do login(admin.user) @@ -102,7 +102,7 @@ post :step, params: params.merge!( step: 5, - transfer: { amount: 3600, reason: "because of reasons" } + transfer: {amount: 3600, reason: 'because of reasons'} ) post :create, params: params @@ -110,8 +110,8 @@ end end - context "non admins" do - it "cannot access step route" do + context 'non admins' do + it 'cannot access step route' do login(member.user) get :step, params: { step: 1 } @@ -119,12 +119,13 @@ expect(response).not_to have_http_status(:success) end - it "cannot access create route" do + it 'cannot access create route' do login(member.user) post :create - expect(response).to redirect_to("/") + expect(response).to redirect_to('/') end end end + diff --git a/spec/controllers/offers_controller_spec.rb b/spec/controllers/offers_controller_spec.rb index bff601f8c..d8b1319e0 100644 --- a/spec/controllers/offers_controller_spec.rb +++ b/spec/controllers/offers_controller_spec.rb @@ -74,13 +74,13 @@ end it "populates an array of offers" do - get :index, params: { q: "compañeros" } + get :index, params: { q: 'compañeros' } expect(assigns(:offers)).to eq([offer]) end it "allows to search by partial word" do - get :index, params: { q: "compañ" } + get :index, params: { q: 'compañ' } expect(assigns(:offers)).to eq([offer]) end @@ -122,48 +122,48 @@ end end - describe "GET #show" do - context "when the user is logged in" do + describe 'GET #show' do + context 'when the user is logged in' do before { login(another_member.user) } - context "when the requested offer" do - context "is not active" do + context 'when the requested offer' do + context 'is not active' do before do offer.active = false offer.save! end - it "renders the 404 page" do + it 'renders the 404 page' do get :show, params: { id: offer.id } expect(response.status).to eq(404) end end - context "is active" do - context "and the user that created the offer is not active anymore" do + context 'is active' do + context 'and the user that created the offer is not active anymore' do before do member.active = false member.save! end - it "renders the 404 page" do + it 'renders the 404 page' do get :show, params: { id: offer.id } expect(response.status).to eq(404) end end - context "and the user that created the offer is active" do - it "renders a successful response" do + context 'and the user that created the offer is active' do + it 'renders a successful response' do get :show, params: { id: offer.id } expect(response.status).to eq(200) end - it "assigns the requested offer to @offer" do + it 'assigns the requested offer to @offer' do get :show, params: { id: offer.id } expect(assigns(:offer)).to eq(offer) end - it "assigns the account destination of the transfer" do + it 'assigns the account destination of the transfer' do get :show, params: { id: offer.id } expect(assigns(:destination_account)).to eq(member.account) end @@ -171,8 +171,8 @@ end end - context "when the user pertains to multiple organizations" do - context "and user's current organization is different than offer's organization" do + context 'when the user pertains to multiple organizations' do + context 'and user\'s current organization is different than offer\'s organization' do let(:another_organization) { Fabricate(:organization) } before do @@ -180,7 +180,7 @@ allow(controller).to receive(:@current_organization).and_return(another_organization) end - it "sets the offer's organization as user's current organization" do + it 'sets the offer\'s organization as user\'s current organization' do get :show, params: { id: offer.id } expect(session[:current_organization_id]).to eq(offer.organization_id) expect(assigns(:current_organization)).to eq(offer.organization) @@ -189,17 +189,18 @@ end end - context "when the user is not a member of the organization where the offer is published" do + context 'when the user is not a member of the organization where the offer is published' do let(:another_user) { Fabricate(:user) } before { login(another_user) } end - context "when the user is not logged in" do - it "assigns the requested offer to @offer" do + context 'when the user is not logged in' do + it 'assigns the requested offer to @offer' do get :show, params: { id: offer.id } expect(assigns(:offer)).to eq(offer) end + end end @@ -211,8 +212,8 @@ expect do post "create", params: { offer: { user: another_member.user, - category_id: test_category, - title: "New title" } } + category_id: test_category, + title: "New title" } } end.to change(Offer, :count).by(1) end end @@ -233,10 +234,10 @@ login(member.user) put "update", params: { id: offer.id, offer: Fabricate.to_params(:offer, - user: member, - title: "New title", - description: "New description", - tag_list: ["foo"]) } + user: member, + title: "New title", + description: "New description", + tag_list: ["foo"]) } offer.reload expect(offer.title).to eq("New title") @@ -252,9 +253,9 @@ login(member.user) put :update, params: { id: offer.id, offer: Fabricate.to_params(:offer, - user: nil, - title: "New title", - description: "New description") } + user: nil, + title: "New title", + description: "New description") } expect(offer.title).not_to eq("New title") expect(offer.description).not_to eq("New description") diff --git a/spec/controllers/organizations_controller_spec.rb b/spec/controllers/organizations_controller_spec.rb index 5f4ecf471..e09b320d7 100644 --- a/spec/controllers/organizations_controller_spec.rb +++ b/spec/controllers/organizations_controller_spec.rb @@ -4,16 +4,16 @@ let(:member) { Fabricate(:member, organization: organization) } let(:user) { member.user } - describe "GET #index" do - context "without parameters" do - it "populates and array of organizations" do + describe 'GET #index' do + context 'without parameters' do + it 'populates and array of organizations' do get :index expect(assigns(:organizations)).to include(organization, second_organization) end end - context "a search is made" do + context 'a search is made' do before do second_organization.name = "Banco del tiempo Doe" second_organization.city = "Sevilla" @@ -25,47 +25,47 @@ organization.save! end - it "populates an array of organizations searching by city" do - get :index, params: { q: "Sevilla" } + it 'populates an array of organizations searching by city' do + get :index, params: { q: 'Sevilla' } expect(assigns(:organizations)).to eq([second_organization]) end - it "populates an array of organizations searching by name" do - get :index, params: { q: "Doe" } + it 'populates an array of organizations searching by name' do + get :index, params: { q: 'Doe' } expect(assigns(:organizations)).to eq([second_organization]) end - it "populates an array of organizations searching by address" do - get :index, params: { q: "gloria" } + it 'populates an array of organizations searching by address' do + get :index, params: { q: 'gloria' } expect(assigns(:organizations)).to eq([second_organization]) end - it "populates an array of organizations searching by neighborhood" do - get :index, params: { q: "Paz" } + it 'populates an array of organizations searching by neighborhood' do + get :index, params: { q: 'Paz' } expect(assigns(:organizations)).to eq([organization, second_organization]) end - it "allows to search by partial word" do - get :index, params: { q: "Sev" } + it 'allows to search by partial word' do + get :index, params: { q: 'Sev' } expect(assigns(:organizations)).to eq([second_organization]) end - it "populates an array of organizations ignoring accents" do - get :index, params: { q: "Sevillá" } + it 'populates an array of organizations ignoring accents' do + get :index, params: { q: 'Sevillá' } expect(assigns(:organizations)).to eq([second_organization]) end end - context "a user is logged" do + context 'a user is logged' do before { login(member.user) } - it "populates an array of user organizations" do + it 'populates an array of user organizations' do get :index expect(assigns(:user_organizations)).to include(member.organization) @@ -74,17 +74,17 @@ end end - describe "GET #show" do - it "displays the organization page" do - get "show", params: { id: organization.id } + describe 'GET #show' do + it 'displays the organization page' do + get 'show', params: { id: organization.id } expect(assigns(:organization)).to eq(organization) expect(response.status).to eq(200) end end - describe "GET #select_organization" do - it "it shows the organizations in which the user is a member" do + describe 'GET #select_organization' do + it 'it shows the organizations in which the user is a member' do login(member.user) get :select_organization @@ -94,35 +94,35 @@ end end - describe "POST #update" do - context "with a logged user (admins organization)" do + describe 'POST #update' do + context 'with a logged user (admins organization)' do let(:member) { Fabricate(:member, organization: organization, manager: true) } - it "allows to update organization" do + it 'allows to update organization' do login(member.user) - post :update, params: { id: organization.id, organization: { name: "New org name" } } + post :update, params: { id: organization.id, organization: { name: 'New org name' } } organization.reload - expect(organization.name).to eq("New org name") + expect(organization.name).to eq('New org name') end end - context "without a logged user" do - it "does not allow to update organization" do - post :update, params: { id: organization.id, organization: { name: "New org name" } } + context 'without a logged user' do + it 'does not allow to update organization' do + post :update, params: { id: organization.id, organization: { name: 'New org name' } } expect(response).to redirect_to(root_path) - expect(flash[:error]).to eq("You are not authorized to perform this action.") + expect(flash[:error]).to eq('You are not authorized to perform this action.') end end end - describe "#set_current" do + describe '#set_current' do before { login(user) } - it "stores the given organization as current organization in session" do - post "set_current", params: { id: organization.id } + it 'stores the given organization as current organization in session' do + post 'set_current', params: { id: organization.id } expect(session[:current_organization_id]).to eq(organization.id) end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index 9abe843b6..eba90f4ed 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -1,12 +1,12 @@ RSpec.describe PagesController do - describe "#show" do - it "renders the page successfully" do + describe '#show' do + it 'renders the page successfully' do get :show, params: { page: :about } expect(response).to render_template(:about) end - it "returns a 404 if the page does not exist" do + it 'returns a 404 if the page does not exist' do get :show, params: { page: :foo } expect(response.status).to eq(404) diff --git a/spec/controllers/petitions_controller_spec.rb b/spec/controllers/petitions_controller_spec.rb index b16c80b2f..0d7bb916c 100644 --- a/spec/controllers/petitions_controller_spec.rb +++ b/spec/controllers/petitions_controller_spec.rb @@ -3,11 +3,11 @@ let(:user) { Fabricate(:user) } let!(:admin) { Fabricate(:member, organization: organization, manager: true) } - describe "POST #create" do + describe 'POST #create' do before { login(user) } - it "creates the petition" do - request.env["HTTP_REFERER"] = organizations_path + it 'creates the petition' do + request.env['HTTP_REFERER'] = organizations_path expect do post :create, params: { user_id: user.id, organization_id: organization.id } @@ -16,34 +16,34 @@ end end - describe "PUT #update" do + describe 'PUT #update' do before { login(admin.user) } - let(:petition) { Petition.create(user: user, organization: organization, status: "pending") } + let(:petition) { Petition.create(user: user, organization: organization, status: 'pending') } - it "decline the petition" do - put :update, params: { status: "declined", id: petition.id } + it 'decline the petition' do + put :update, params: { status: 'declined', id: petition.id } petition.reload - expect(petition.status).to eq("declined") + expect(petition.status).to eq('declined') end - it "accept the petition and add the user to the org" do - put :update, params: { status: "accepted", id: petition.id } + it 'accept the petition and add the user to the org' do + put :update, params: { status: 'accepted', id: petition.id } petition.reload expect(user.members.last.organization.id).to eq(organization.id) - expect(petition.status).to eq("accepted") + expect(petition.status).to eq('accepted') end end - describe "GET #manage" do + describe 'GET #manage' do before do allow(controller).to receive(:current_organization) { organization } login(admin.user) end - let!(:petition) { Petition.create(user: user, organization: organization, status: "pending") } + let!(:petition) { Petition.create(user: user, organization: organization, status: 'pending') } - it "populates a list of users with pending petitions" do + it 'populates a list of users with pending petitions' do get :manage expect(assigns(:users)).to include(user) diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index 231f92749..369402369 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -23,20 +23,20 @@ end end - context "with a logged user" do + context 'with a logged user' do before { login(member1.user) } - describe "GET #user_list" do - it "downloads a csv" do - get :user_list, params: { format: "csv" } + describe 'GET #user_list' do + it 'downloads a csv' do + get :user_list, params: { format: 'csv' } report = Report::Csv::Member.new(test_organization, test_organization.members.active) expect(response.body).to match(report.run) expect(response.media_type).to eq("text/csv") end - it "downloads a pdf" do - get :user_list, params: { format: "pdf" } + it 'downloads a pdf' do + get :user_list, params: { format: 'pdf' } report = Report::Pdf::Member.new(test_organization, test_organization.members.active) expect(response.body).to eq(report.run) @@ -44,27 +44,27 @@ end end - describe "GET #post_list" do + describe 'GET #post_list' do let(:report_posts) { test_organization.posts.of_active_members.group_by(&:category) } - it "do NOT show the inactive members" do - get :post_list, params: { type: "offer" } + it 'do NOT show the inactive members' do + get :post_list, params: { type: 'offer' } posts = assigns(:posts)[0][1] expect(posts.size).to eq(active_organization_offers.size) expect(posts.map(&:id)).to match_array(active_organization_offers.map(&:id)) end - it "downloads a csv" do - get :post_list, params: { type: "offer", format: "csv" } + it 'downloads a csv' do + get :post_list, params: { type: 'offer', format: 'csv' } report = Report::Csv::Post.new(test_organization, report_posts, Offer) expect(response.body).to eq(report.run) expect(response.media_type).to eq("text/csv") end - it "downloads a pdf" do - get :post_list, params: { type: "offer", format: "pdf" } + it 'downloads a pdf' do + get :post_list, params: { type: 'offer', format: 'pdf' } report = Report::Pdf::Post.new(test_organization, report_posts, Offer) expect(response.body).to eq(report.run) @@ -72,17 +72,17 @@ end end - describe "GET #transfer_list" do - it "downloads a csv" do - get :transfer_list, params: { format: "csv" } + describe 'GET #transfer_list' do + it 'downloads a csv' do + get :transfer_list, params: { format: 'csv' } report = Report::Csv::Transfer.new(test_organization, test_organization.all_transfers) expect(response.body).to eq(report.run) expect(response.media_type).to eq("text/csv") end - it "downloads a pdf" do - get :transfer_list, params: { format: "pdf" } + it 'downloads a pdf' do + get :transfer_list, params: { format: 'pdf' } report = Report::Pdf::Transfer.new(test_organization, test_organization.all_transfers) expect(response.body).to eq(report.run) @@ -90,18 +90,18 @@ end end - describe "GET #download_all" do - it "downloads a zip" do + describe 'GET #download_all' do + it 'downloads a zip' do get :download_all - expect(response.media_type).to eq("application/zip") - expect(response.body).to include("Inquiries") - expect(response.body).to include("Offers") - expect(response.body).to include("Members") - expect(response.body).to include("Transfers") + expect(response.media_type).to eq('application/zip') + expect(response.body).to include('Inquiries') + expect(response.body).to include('Offers') + expect(response.body).to include('Members') + expect(response.body).to include('Transfers') end - it "redirects to download_all_report_path (retry) if zip is not ready" do + it 'redirects to download_all_report_path (retry) if zip is not ready' do allow(subject).to receive(:add_csv_to_zip).and_raise(Errno::ENOENT) get :download_all diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index d65837b54..aa52e9a52 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -1,18 +1,18 @@ RSpec.describe SessionsController do - let(:user) { Fabricate(:user, password: "papapa22", password_confirmation: "papapa22") } + let(:user) { Fabricate(:user, password: 'papapa22', password_confirmation: 'papapa22') } before do request.env["devise.mapping"] = Devise.mappings[:user] end - describe "#create" do - it "does not show a notice flash message" do + describe '#create' do + it 'does not show a notice flash message' do post :create, params: { user: { email: user.email, password: user.password } } expect(flash[:notice]).to be_nil end - it "redirects to the previous page" do + it 'redirects to the previous page' do session["user_return_to"] = offers_path post :create, params: { user: { email: user.email, password: user.password } } @@ -21,12 +21,12 @@ end end - describe "#destroy" do + describe '#destroy' do before do post :create, params: { user: { email: user.email, password: user.password } } end - it "does not show a notice flash message" do + it 'does not show a notice flash message' do delete :destroy expect(flash[:notice]).to be_nil diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 690c3e816..9907d7bc0 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -1,12 +1,12 @@ RSpec.describe StatisticsController do let(:organization) { Fabricate(:organization) } - let(:user) { Fabricate(:user, date_of_birth: "1980-1-1", gender: "others") } + let(:user) { Fabricate(:user, date_of_birth: '1980-1-1', gender: 'others') } let(:member) { Fabricate(:member, organization: organization, user: user) } before(:each) { login(member.user) } - describe "GET #all_transfers" do - it "populates all transfers from current organization" do + describe 'GET #all_transfers' do + it 'populates all transfers from current organization' do transfer = Fabricate(:transfer, source: organization.account, destination: member.account) transfer2 = Fabricate(:transfer) @@ -16,8 +16,8 @@ end end - describe "GET #global_activity" do - it "populates some variables" do + describe 'GET #global_activity' do + it 'populates some variables' do 2.times { Fabricate(:transfer, source: organization.account, destination: member.account) } get :global_activity @@ -27,24 +27,22 @@ end end - describe "GET #type_swaps" do - it "populates offers variable" do + describe 'GET #type_swaps' do + it 'populates offers variable' do category = Fabricate(:category) - Fabricate(:offer, organization: organization, user: member.user, category: category, - tag_list: ["foo"]) - Fabricate(:transfer, source: organization.account, destination: member.account, - post: Offer.all.sample) + Fabricate(:offer, organization: organization, user: member.user, category: category, tag_list: ["foo"]) + Fabricate(:transfer, source: organization.account, destination: member.account, post: Offer.all.sample) get :type_swaps expect(assigns(:offers)).to eq([ - [category.name, "foo", 10, 1, 1.0] - ]) + [category.name, "foo", 10, 1, 1.0] + ]) end end - describe "GET #demographics" do - it "populates age_counts and gender_counts variables" do + describe 'GET #demographics' do + it 'populates age_counts and gender_counts variables' do get :demographics expect(assigns(:age_counts)).to eq({ "35-44" => 1 }) diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 8048c072a..412445d88 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -5,9 +5,7 @@ let (:organization) { Fabricate(:organization) } let (:member) { Fabricate(:member, organization: organization, tags: member_tags) } let! (:offer) { Fabricate(:offer, user: member.user, organization: organization, tags: tags) } - let! (:inquiry) do - Fabricate(:inquiry, user: member.user, organization: organization, tags: more_tags) - end + let! (:inquiry) { Fabricate(:inquiry, user: member.user, organization: organization, tags: more_tags) } before(:each) do login(member.user) @@ -55,27 +53,27 @@ get :alpha_grouped_index expect(assigns(:tags)).to eq({ - "H" => [["html", 2], ["html5", 1]], - "C" => [["css", 1]] - }) + "H" => [["html", 2], ["html5", 1]], + "C" => [["css", 1]] + }) end it "load offer tags" do get :alpha_grouped_index, params: { post_type: "offer" } expect(assigns(:tags)).to eq({ - "B" => [["bar", 1], ["baz", 1]], - "F" => [["foo", 1]] - }) + "B" => [["bar", 1], ["baz", 1]], + "F" => [["foo", 1]] + }) end it "load inquiries tags" do get :alpha_grouped_index, params: { post_type: "inquiry" } expect(assigns(:tags)).to eq({ - "J" => [["js", 1]], - "R" => [["rails", 1], ["ruby", 1]] - }) + "J" => [["js", 1]], + "R" => [["rails", 1], ["ruby", 1]] + }) end it "renders a partial with format js" do diff --git a/spec/controllers/transfers_controller_spec.rb b/spec/controllers/transfers_controller_spec.rb index af00858bd..a034f778c 100644 --- a/spec/controllers/transfers_controller_spec.rb +++ b/spec/controllers/transfers_controller_spec.rb @@ -4,12 +4,12 @@ let (:member_giver) { Fabricate(:member, organization: test_organization) } let (:member_taker) { Fabricate(:member, organization: test_organization) } - describe "#new" do + describe '#new' do let(:user) { member_giver.user } before { login(user) } - context "when the destination is a user account" do + context 'when the destination is a user account' do let(:user_account) do user.members.find_by(organization: user.organizations.first).account end @@ -20,48 +20,48 @@ } end - it "finds the accountable" do + it 'finds the accountable' do get :new, params: params - expect(response.body). - to include("#{member_giver.display_name_with_uid}") + expect(response.body) + .to include("#{member_giver.display_name_with_uid}") end - it "finds the destination account" do + it 'finds the destination account' do get :new, params: params expect(response.body).to include("") end - it "builds a transfer with the id of the destination" do + it 'builds a transfer with the id of the destination' do get :new, params: params - expect(response.body). - to include("") + expect(response.body) + .to include("") end - context "when the offer is specified" do + context 'when the offer is specified' do let(:offer) { Fabricate(:offer, organization: user.organizations.first) } - it "finds the transfer offer" do + it 'finds the transfer offer' do get :new, params: params.merge(offer: offer.id) expect(response.body).to include("