diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..934ca8db9 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,206 @@ +AllCops: + TargetRubyVersion: 2.4 + DisabledByDefault: true + +#################### Layout ############################### + +Layout/AccessModifierIndentation: + Description: Check indentation of private/protected visibility modifiers. + StyleGuide: '#indent-public-private-protected' + Enabled: true + +Layout/InitialIndentation: + Description: >- + Checks the indentation of the first non-blank non-comment line in a file. + Enabled: true + +Layout/IndentationWidth: + Description: "Use 2 spaces for indentation." + StyleGuide: "#spaces-indentation" + Enabled: true + +Layout/IndentationConsistency: + Description: 'Keep indentation straight.' + StyleGuide: '#spaces-indentation' + Enabled: true + +Layout/CaseIndentation: + Description: "Indentation of when in a case/when/[else/]end." + StyleGuide: "#indent-when-to-case" + Enabled: true + +Layout/ElseAlignment: + Description: 'Align elses and elsifs correctly.' + Enabled: true + +Layout/EmptyLinesAroundAccessModifier: + Description: "Keep blank lines around access modifiers." + StyleGuide: "#empty-lines-around-access-modifier" + Enabled: true + +Lint/EndAlignment: + Description: 'Align ends correctly.' + Enabled: true + +Layout/EndOfLine: + Description: "Use Unix-style line endings." + StyleGuide: "#crlf" + Enabled: true + +Layout/ExtraSpacing: + Description: "Do not use unnecessary spacing." + Enabled: true + +Layout/LeadingCommentSpace: + Description: "Comments should start with a space." + StyleGuide: "#hash-space" + Enabled: true + +Layout/SpaceAfterColon: + Description: "Use spaces after colons." + StyleGuide: "#spaces-operators" + Enabled: true + +Layout/SpaceAfterComma: + Description: "Use spaces after commas." + StyleGuide: '#spaces-operators' + Enabled: true + +Layout/SpaceAfterMethodName: + Description: >- + Do not put a space between a method name and the opening + parenthesis in a method definition. + StyleGuide: "#parens-no-spaces" + Enabled: true + +Layout/SpaceAfterNot: + Description: Tracks redundant space after the ! operator. + StyleGuide: "#no-space-bang" + Enabled: true + +Layout/SpaceAfterSemicolon: + Description: "Use spaces after semicolons." + StyleGuide: '#spaces-operators' + Enabled: true + +Layout/SpaceBeforeComma: + Description: "No spaces before commas." + Enabled: true + +Layout/SpaceBeforeComment: + Description: >- + Checks for missing space between code and a comment on the + same line. + Enabled: true + +Layout/SpaceBeforeSemicolon: + Description: "No spaces before semicolons." + Enabled: true + +Layout/SpaceAroundOperators: + Description: "Use a single space around operators." + StyleGuide: "#spaces-operators" + Enabled: true + +Layout/Tab: + Description: "No hard tabs." + StyleGuide: "#spaces-indentation" + Enabled: true + +Layout/TrailingBlankLines: + Description: "Checks trailing blank lines and final newline." + StyleGuide: '#newline-eof' + Enabled: true + +Layout/TrailingWhitespace: + Description: "Avoid trailing whitespace." + StyleGuide: "#no-trailing-whitespace" + Enabled: true + +#################### Naming ############################## + +Naming/ClassAndModuleCamelCase: + Description: "Use CamelCase for classes and modules." + StyleGuide: "#camelcase-classes" + Enabled: true + +Naming/ConstantName: + Description: "Constants should use SCREAMING_SNAKE_CASE." + StyleGuide: "#screaming-snake-case" + Enabled: true + +#################### Style ############################### + +Style/ClassVars: + Description: 'Avoid the use of class variables.' + StyleGuide: '#no-class-vars' + Enabled: true + +Style/DefWithParentheses: + Description: "Use def with parentheses when there are arguments." + StyleGuide: "#method-parens" + Enabled: true + +Style/Encoding: + Description: "Use UTF-8 as the source file encoding." + StyleGuide: "#utf-8" + Enabled: true + +# TODO +Style/FrozenStringLiteralComment: + Description: "Add frozen_string_literal comment to the top of files" + Include: + - "app/**/*.rb" + - "lib/**/*.rb" + Enabled: false + +Style/HashSyntax: + Description: "Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2}" + EnforcedStyle: ruby19 + +Style/IfInsideElse: + Description: "Finds if nodes inside else, which can be converted to elsif." + Enabled: true + +Style/MethodCallWithoutArgsParentheses: + Description: "Do not use parentheses for method calls with no arguments." + StyleGuide: "#method-invocation-parens" + Enabled: true + +Style/MethodDefParentheses: + Description: >- + Checks if the method definitions have or don't have + parentheses. + StyleGuide: "#method-parens" + Enabled: true + +Style/RedundantReturn: + Description: "Don't use return where it's not required." + Enabled: true + +Style/RedundantSelf: + Description: "Don't use self where it's not needed." + Enabled: true + +Style/TrailingCommaInArguments: + Description: "Checks for trailing comma in argument lists." + StyleGuide: "#no-trailing-params-comma" + Enabled: true + +#################### Metrics ############################### + +# TODO +Metrics/LineLength: + Description: "Limit lines to 80 characters." + StyleGuide: "#80-character-limits" + Enabled: false + + +#################### Bundler ############################### + +Bundler/DuplicatedGem: + Description: "Checks for duplicate gem entries in Gemfile." + Enabled: true + Include: + - "**/Gemfile" + - "**/gems.rb" diff --git a/.travis.yml b/.travis.yml index 970cfbcab..570e4c671 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,9 @@ before_script: - bundle exec rake db:create db:schema:load RAILS_ENV=test - npm install -g jshint script: -- bundle exec rake spec +- bundle exec rubocop - jshint app/assets/javascripts +- bundle exec rake spec deploy: - provider: heroku api_key: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ceca93113..fb0e7dd76 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,9 +72,7 @@ Before you start working, make sure no one else is already working on it: check If you've confirmed that no one is working on the issue and would like to give it a go, feel free to leave a comment saying so! You could write something like the following: -``` - I think I know how to fix this one! Will give it a try :thumbsup: -``` + I think I know how to fix this one! Will give it a try :thumbsup: ### Creating a Pull Request @@ -94,7 +92,8 @@ If you've cloned the app a while ago, you want to make sure that your cloned `ma ### Write Code -We aim to follow the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) but we don't enforce it (i.e. there is no [RuboCop](https://github.com/bbatsov/rubocop)). The most important thing is probably just proper indentation: two whitespaces. +We aim to follow the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) and have [RuboCop](https://github.com/bbatsov/rubocop) set up to make sure we stay consistent with some basic rules (see our [rubocop.yml](https://github.com/rails-girls-summer-of-code/rgsoc-teams/blob/master/.rubocop.yml) file for details). +But don't be afraid, those are friendly cops who are here to help you with formatting your code 👮 We prefer JavaScript (`*.js`) over CoffeeScript (`*.coffee`). jQuery is perfectly fine, but if you can, use [Vanilla JS instead of jQuery](https://gist.github.com/liamcurry/2597326). Indentation for JavaScript files: four whitespaces. @@ -106,7 +105,7 @@ Make atomic commits with a descriptive commit message. ### Make a Pull Request -Github [provides documentation](https://help.github.com/articles/creating-a-pull-request/) on how to create a PR. A new PR (and any subsequent updates to it) will trigger running the test suite on Travis CI. +Github [provides documentation](https://help.github.com/articles/creating-a-pull-request/) on how to create a PR. A new PR (and any subsequent updates to it) will trigger running the test suite and automatic code analyzers on Travis CI. If your contribution alters the way the Teams App looks (e.g. CSS changes), we kindly ask you to provide a few screenshots (before/after) that illustrate the change. It's much easier and quicker to review as we won't have to checkout the PR locally. You can drag'n'drop image files directly into the PR description or its comments section. diff --git a/Gemfile b/Gemfile index c29f80513..6d7356c5e 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ group :development, :test do gem 'rspec-rails' gem 'factory_girl_rails' gem 'database_cleaner' - gem 'byebug', require: !ENV['RM_INFO'] #require parameter is workaround for RubyMine with Rails ~> 4.1 + gem 'byebug', require: !ENV['RM_INFO'] # require parameter is workaround for RubyMine with Rails ~> 4.1 gem 'ffaker' end @@ -70,4 +70,5 @@ group :test do gem 'rspec-collection_matchers' gem 'rspec-html-matchers' gem 'rspec-activemodel-mocks' + gem 'rubocop', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 35e892dc1..26179f1b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,7 @@ GEM tzinfo (~> 1.1) addressable (2.4.0) arel (8.0.0) + ast (2.3.0) autoprefixer-rails (7.1.4) execjs aws-sdk (2.10.29) @@ -194,7 +195,11 @@ GEM oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) + parallel (1.12.0) + parser (2.4.0.0) + ast (~> 2.2) pg (0.21.0) + powerpack (0.1.1) pretender (0.3.1) actionpack pry (0.10.4) @@ -239,6 +244,8 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (2.2.2) + rake rake (12.1.0) rb-fsevent (0.10.2) rb-inotify (0.9.10) @@ -277,6 +284,14 @@ GEM rspec-mocks (~> 3.6.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) + rubocop (0.50.0) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.3) safe_yaml (1.0.4) sass (3.5.1) sass-listen (~> 4.0.0) @@ -342,6 +357,7 @@ GEM thread_safe (~> 0.1) uglifier (3.2.0) execjs (>= 0.3.0, < 3) + unicode-display_width (1.3.0) unicode_utils (1.4.0) warden (1.2.7) rack (>= 1.0) @@ -396,6 +412,7 @@ DEPENDENCIES rspec-collection_matchers rspec-html-matchers rspec-rails + rubocop sass-rails sentry-raven shoulda diff --git a/README.md b/README.md index 359635498..1f97df1e1 100644 --- a/README.md +++ b/README.md @@ -73,28 +73,18 @@ Copy `config/database.yml.example` to `config/database.yml`. Then make sure you modify the settings so it could connect to your postgres server. Inside database.yml add username and password for development and test: -``` -development: - adapter: postgresql - database: rgsocteams_development - host: localhost - username: rgsoc - password: rgsoc -``` -Then install all dependencies: - -```bash -bundle install -bundle exec rake db:drop db:setup -``` -**Note for OS X:** There is a bug where on OS X you need to force 64bit mode for `bundle install`: + development: + adapter: postgresql + database: rgsocteams_development + host: localhost + username: rgsoc + password: rgsoc -```bash -ARCHFLAGS="-arch x86_64" bundle install -``` +Then install all dependencies: -Otherwise pg gem installation will fail. + bundle install + bundle exec rails db:setup ### Mailtrap (optional) @@ -162,29 +152,35 @@ as someone else. Go to http://localhost:3000/users while logged in to do that. ## Testing -```bash -bundle exec rake spec -``` + bundle exec rake spec You can optionally create a test-coverage report in `coverage/*` like so: -```bash -COVERAGE=yes bundle exec rake spec -``` + COVERAGE=yes bundle exec rake spec + +### Code Analyzation + +You can run automatic code analyzers to check if your code complies to the project's guidelines and general best practice. + +For Ruby code: + + bundle exec rubocop + +For Javascript code: _(you need to install [`jshint`](http://jshint.com/install/) first)_ + + jshint app/assets/javascript ## Deployment -The staging app lives at http://rgsoc-teams-staging.herokuapp.com/users. The production app is +The staging app lives at http://rgsoc-teams-staging.herokuapp.com. The production app is at http://teams.railsgirlssummerofcode.org. -``` -[remote "staging"] - url = git@heroku.com:rgsoc-teams-staging.git - fetch = +refs/heads/*:refs/remotes/staging/* -[remote "production"] - url = git@heroku.com:rgsoc-teams-production.git - fetch = +refs/heads/*:refs/remotes/production/* -``` + [remote "staging"] + url = git@heroku.com:rgsoc-teams-staging.git + fetch = +refs/heads/*:refs/remotes/staging/* + [remote "production"] + url = git@heroku.com:rgsoc-teams-production.git + fetch = +refs/heads/*:refs/remotes/production/* Append `-r staging` or `-r production` to any `heroku` command in order to specify the app. diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 402309a4c..baa6959fe 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -11,7 +11,7 @@ def index respond_to do |format| format.html format.json { render json: @activities } - format.atom { render layout: false } + format.atom { render layout: false } end end diff --git a/app/controllers/application_drafts_controller.rb b/app/controllers/application_drafts_controller.rb index d2ebc48a4..1f8d5a2d1 100644 --- a/app/controllers/application_drafts_controller.rb +++ b/app/controllers/application_drafts_controller.rb @@ -64,7 +64,7 @@ def apply flash[:notice] = 'Your application has been submitted!' ApplicationFormMailer.new_application(application_draft.application).deliver_later else - flash[:alert] = 'An error has occurred. Please contact us.' + flash[:alert] = 'An error has occurred. Please contact us.' end redirect_to application_drafts_path else diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 225487d17..1738828a7 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -25,11 +25,12 @@ def create end private - def comment_params - params.require(:comment).permit(:commentable_id, :commentable_type, :text).merge(user_id: current_user.id) - end - def commentable_path(commentable, anchor) - self.class::PATH_PARENTS + [commentable, anchor: anchor] - end + def comment_params + params.require(:comment).permit(:commentable_id, :commentable_type, :text).merge(user_id: current_user.id) + end + + def commentable_path(commentable, anchor) + self.class::PATH_PARENTS + [commentable, anchor: anchor] + end end diff --git a/app/controllers/community_controller.rb b/app/controllers/community_controller.rb index 7c2004ec6..7d9beea63 100644 --- a/app/controllers/community_controller.rb +++ b/app/controllers/community_controller.rb @@ -9,7 +9,7 @@ def index mentoring: 'Helping as a Mentor', organizing: 'Helping as an Organizer' } - @users = User.ordered(params[:sort],params[:direction]) + @users = User.ordered(params[:sort], params[:direction]) .group('users.id').with_all_associations_joined @users = @users.with_assigned_roles if Time.now.utc > (current_season.starts_at || Date.new) @users = @users.with_role(params[:role]) if params[:role].present? && params[:role] != 'all' @@ -22,4 +22,4 @@ def index def normalize_params params[:role] = 'all' if params[:role].blank? end -end \ No newline at end of file +end diff --git a/app/controllers/conference_attendances_controller.rb b/app/controllers/conference_attendances_controller.rb index 1a156c3fc..fa0ca700c 100644 --- a/app/controllers/conference_attendances_controller.rb +++ b/app/controllers/conference_attendances_controller.rb @@ -11,7 +11,8 @@ def update end private - def attendance_params - params.require(:conference_attendance).permit(:attendance) - end + + def attendance_params + params.require(:conference_attendance).permit(:attendance) + end end diff --git a/app/controllers/join_controller.rb b/app/controllers/join_controller.rb index 51d7a26b6..d759dff31 100644 --- a/app/controllers/join_controller.rb +++ b/app/controllers/join_controller.rb @@ -9,11 +9,11 @@ def create private - def set_team - @team = Team.find(params[:team_id]) - end + def set_team + @team = Team.find(params[:team_id]) + end - def allow_helpdesk - redirect_to root_url unless @team.helpdesk? - end + def allow_helpdesk + redirect_to root_url unless @team.helpdesk? + end end diff --git a/app/controllers/mentor/comments_controller.rb b/app/controllers/mentor/comments_controller.rb index d5a108b4c..097f61d54 100644 --- a/app/controllers/mentor/comments_controller.rb +++ b/app/controllers/mentor/comments_controller.rb @@ -22,7 +22,7 @@ def update_params end def path_for(comment) - anchor = ActionView::RecordIdentifier.dom_id(comment) + anchor = ActionView::RecordIdentifier.dom_id(comment) mentor_application_path( id: comment.commentable_id, anchor: anchor) end diff --git a/app/controllers/orga/conferences_controller.rb b/app/controllers/orga/conferences_controller.rb index ccb5d7063..29f0e2c2e 100644 --- a/app/controllers/orga/conferences_controller.rb +++ b/app/controllers/orga/conferences_controller.rb @@ -55,7 +55,7 @@ def conference_params :url, :twitter, :starts_on, :ends_on, :round, :lightningtalkslots, :tickets, :flights, :accomodation, - :gid, #id in orga's Google Spreadsheet (format: 2017001) + :gid, # id in orga's Google Spreadsheet (format: 2017001) :notes, conference_preferences_attributes: [:id, :_destroy] ) diff --git a/app/controllers/orga/submissions_controller.rb b/app/controllers/orga/submissions_controller.rb index 69fe3dfb4..278552bdd 100644 --- a/app/controllers/orga/submissions_controller.rb +++ b/app/controllers/orga/submissions_controller.rb @@ -22,4 +22,3 @@ def find_mailing @mailing = Mailing.find(params[:mailing_id]) end end - diff --git a/app/controllers/orga/users_info_controller.rb b/app/controllers/orga/users_info_controller.rb index 54506013c..bfe493b5d 100644 --- a/app/controllers/orga/users_info_controller.rb +++ b/app/controllers/orga/users_info_controller.rb @@ -1,18 +1,18 @@ class Orga::UsersInfoController < Orga::BaseController before_action :normalize_params, only: :index - + private - def users - users = User.includes(:teams).ordered - users = users.with_role(params[:role]) if params[:role].present? && params[:role] != 'all' - users = users.with_team_kind(params[:kind]) if params[:kind].present? && params[:kind] != 'all' - users - end - helper_method :users + def users + users = User.includes(:teams).ordered + users = users.with_role(params[:role]) if params[:role].present? && params[:role] != 'all' + users = users.with_team_kind(params[:kind]) if params[:kind].present? && params[:kind] != 'all' + users + end + helper_method :users - def normalize_params - params[:role] = 'all' if params[:role].blank? - params[:kind] = 'all' if params[:kind].blank? - end + def normalize_params + params[:role] = 'all' if params[:role].blank? + params[:kind] = 'all' if params[:kind].blank? + end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 9f7e052fd..fa62527e8 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -9,11 +9,11 @@ def show private - def page - params[:page].split('/').last - end + def page + params[:page].split('/').last + end - def layout - LAYOUTS[params[:page].to_sym] || 'application' - end + def layout + LAYOUTS[params[:page].to_sym] || 'application' + end end diff --git a/app/controllers/rating/comments_controller.rb b/app/controllers/rating/comments_controller.rb index 1d8cc27ea..ca2142733 100644 --- a/app/controllers/rating/comments_controller.rb +++ b/app/controllers/rating/comments_controller.rb @@ -1,3 +1,3 @@ class Rating::CommentsController < CommentsController PATH_PARENTS = [:rating] -end \ No newline at end of file +end diff --git a/app/controllers/rating/ratings_controller.rb b/app/controllers/rating/ratings_controller.rb index 39d7c21a8..351b52209 100644 --- a/app/controllers/rating/ratings_controller.rb +++ b/app/controllers/rating/ratings_controller.rb @@ -14,16 +14,17 @@ def update end private - def new_rating_params - params.require(:rating).permit(:rateable_id, :rateable_type, :like, :pick, Rating::FIELDS.keys) - end - def rating_attr_params - params.require(:rating).permit(:like, :pick, Rating::FIELDS.keys) - end + def new_rating_params + params.require(:rating).permit(:rateable_id, :rateable_type, :like, :pick, Rating::FIELDS.keys) + end + + def rating_attr_params + params.require(:rating).permit(:like, :pick, Rating::FIELDS.keys) + end - def find_or_create_rating - rateable_args = new_rating_params.values_at(:rateable_type, :rateable_id) - Rating.by(current_user).for(*rateable_args).first_or_create - end + def find_or_create_rating + rateable_args = new_rating_params.values_at(:rateable_type, :rateable_id) + Rating.by(current_user).for(*rateable_args).first_or_create + end end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 6cfba5d97..43f997723 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -51,21 +51,21 @@ def destroy private - def set_team - @team = Team.find(params[:team_id]) - end + def set_team + @team = Team.find(params[:team_id]) + end - def set_role - @role = if params[:id] - @team.roles.find(params[:id]) - else - @team.roles.new(role_params) - end - end + def set_role + @role = if params[:id] + @team.roles.find(params[:id]) + else + @team.roles.new(role_params) + end + end - def role_params - params[:role] ||= { name: params[:name] } - params.require(:role).permit(:user_id, :team_id, :name, :github_handle, :confirm) - end + def role_params + params[:role] ||= { name: params[:name] } + params.require(:role).permit(:user_id, :team_id, :name, :github_handle, :confirm) + end end diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index f8e17805c..7693b005a 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -54,29 +54,29 @@ def destroy private - def set_team - @team = Team.find(params[:team_id]) if params[:team_id] - end + def set_team + @team = Team.find(params[:team_id]) if params[:team_id] + end - def set_sources - @sources = if @team - @team.sources - else - options = { kind: params[:kind] } if params[:kind].present? - Source.where(options || {}).order(:url) - end - end + def set_sources + @sources = if @team + @team.sources + else + options = { kind: params[:kind] } if params[:kind].present? + Source.where(options || {}).order(:url) + end + end - def set_source - @source = if params[:id] - @team.sources.find(params[:id]) - else - @team.sources.new(source_params) - end - end + def set_source + @source = if params[:id] + @team.sources.find(params[:id]) + else + @team.sources.new(source_params) + end + end - def source_params - params[:source] ||= { url: params[:url] } - params.require(:source).permit(:url, :kind) - end + def source_params + params[:source] ||= { url: params[:url] } + params.require(:source).permit(:url, :kind) + end end diff --git a/app/controllers/status_update_comments_controller.rb b/app/controllers/status_update_comments_controller.rb index 69c1e2187..f434e29cf 100644 --- a/app/controllers/status_update_comments_controller.rb +++ b/app/controllers/status_update_comments_controller.rb @@ -18,4 +18,4 @@ def comment_params params.require(:comment).permit(:commentable_id, :commentable_type, :text).merge(user_id: current_user.id) end -end \ No newline at end of file +end diff --git a/app/controllers/students/status_updates_controller.rb b/app/controllers/students/status_updates_controller.rb index 37eccb2f2..fd680a4fb 100644 --- a/app/controllers/students/status_updates_controller.rb +++ b/app/controllers/students/status_updates_controller.rb @@ -62,8 +62,8 @@ def status_update_params private def status_updates - #order = DESC; set in model + # order = DESC; set in model @status_updates ||= current_team.status_updates.ordered end -end \ No newline at end of file +end diff --git a/app/controllers/supervisor/base_controller.rb b/app/controllers/supervisor/base_controller.rb index c6572f6ff..59578b1df 100644 --- a/app/controllers/supervisor/base_controller.rb +++ b/app/controllers/supervisor/base_controller.rb @@ -12,7 +12,7 @@ def must_be_supervisor end def supervised_teams - @supervised_teams = current_user.teams.where(:roles => { name: 'supervisor' }, :season_id => Season.current.id) + @supervised_teams = current_user.teams.where(roles: { name: 'supervisor' }, season_id: Season.current.id) end -end \ No newline at end of file +end diff --git a/app/controllers/supervisor/comments_controller.rb b/app/controllers/supervisor/comments_controller.rb index 5fe1e87f9..c1758c812 100644 --- a/app/controllers/supervisor/comments_controller.rb +++ b/app/controllers/supervisor/comments_controller.rb @@ -8,19 +8,19 @@ def create comment = Comment.new(comment_params) # Now that we are saving 'checks' without comment text too, we can list them in the view with the text comments. # For the user, checks with or without text are treated the same (except for the mailer). - authorize! :supervise, comment.commentable, :message => "Only a team's own supervisor can comment on the team" - if comment.save - if comment.text.present? - CommentMailer.email(comment).deliver_later - end - else - flash[:alert] = "O no! We can't save your text. Please try again?" + authorize! :supervise, comment.commentable, message: "Only a team's own supervisor can comment on the team" + if comment.save + if comment.text.present? + CommentMailer.email(comment).deliver_later end + else + flash[:alert] = "O no! We can't save your text. Please try again?" + end redirect_to supervisor_path end -private + private def comment_params params.require(:comment).permit(:commentable_id, :commentable_type, :text).merge(user_id: current_user.id) diff --git a/app/controllers/supervisor/notes_controller.rb b/app/controllers/supervisor/notes_controller.rb index 2f418909d..f5393ea43 100644 --- a/app/controllers/supervisor/notes_controller.rb +++ b/app/controllers/supervisor/notes_controller.rb @@ -16,4 +16,4 @@ def notepad_params params.require(:note).permit(:body) end -end \ No newline at end of file +end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 4842e8066..6273deb75 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -73,43 +73,43 @@ def destroy private - def set_team - @team = Team.find(params[:id]) - end + def set_team + @team = Team.find(params[:id]) + end - def set_users - @users = User.order(:github_handle) - end + def set_users + @users = User.order(:github_handle) + end - def team_params - params[:team].fetch(:sources_attributes, {}).delete_if { |key, source| source[:url].empty? } - params.require(:team).permit( - :name, :twitter_handle, :github_handle, :description, :post_info, :event_id, - :checked, :'starts_on(1i)', :'starts_on(2i)', :'starts_on(3i)', - :'finishes_on(1i)', :'finishes_on(2i)', :'finishes_on(3i)', :invisible, - :project_name, - roles_attributes: role_attributes_list, - conference_preference_attributes: [:id, :terms_of_ticket, :terms_of_travel, :first_conference_id, :second_conference_id, :lightning_talk, :comment, :_destroy], - sources_attributes: [:id, :kind, :url, :_destroy] - ) - end + def team_params + params[:team].fetch(:sources_attributes, {}).delete_if { |key, source| source[:url].empty? } + params.require(:team).permit( + :name, :twitter_handle, :github_handle, :description, :post_info, :event_id, + :checked, :'starts_on(1i)', :'starts_on(2i)', :'starts_on(3i)', + :'finishes_on(1i)', :'finishes_on(2i)', :'finishes_on(3i)', :invisible, + :project_name, + roles_attributes: role_attributes_list, + conference_preference_attributes: [:id, :terms_of_ticket, :terms_of_travel, :first_conference_id, :second_conference_id, :lightning_talk, :comment, :_destroy], + sources_attributes: [:id, :kind, :url, :_destroy] + ) + end - def conference_list - Conference.in_current_season - end + def conference_list + Conference.in_current_season + end - def role_attributes_list - unless current_user.admin? || - # If it contains an ID, the user is updating an existing role - params.fetch(:roles_attributes, {}).to_unsafe_h.none? { |_, attributes| attributes.has_key? 'id' } - [:id, :github_handle, :_destroy] # do not allow to update the actual role - else - [:id, :name, :github_handle, :_destroy] - end + def role_attributes_list + unless current_user.admin? || + # If it contains an ID, the user is updating an existing role + params.fetch(:roles_attributes, {}).to_unsafe_h.none? { |_, attributes| attributes.has_key? 'id' } + [:id, :github_handle, :_destroy] # do not allow to update the actual role + else + [:id, :name, :github_handle, :_destroy] end + end - def set_display_roles - @display_roles = ['student'] - @display_roles.map!(&:pluralize) - end + def set_display_roles + @display_roles = ['student'] + @display_roles.map!(&:pluralize) + end end diff --git a/app/controllers/teams_info_controller.rb b/app/controllers/teams_info_controller.rb index 095998de8..4d2b3710a 100644 --- a/app/controllers/teams_info_controller.rb +++ b/app/controllers/teams_info_controller.rb @@ -4,14 +4,13 @@ class TeamsInfoController < ApplicationController private - def teams - Team.ordered - end - helper_method :teams + def teams + Team.ordered + end + helper_method :teams # def normalize_params # params[:role] = 'all' if params[:role].blank? # params[:kind] = 'all' if params[:kind].blank? # end end - diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b0d1a45bb..1bd4b075a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -74,36 +74,36 @@ def resend_confirmation_instruction private - def set_user - @user = User.find(params[:id]) - end + def set_user + @user = User.find(params[:id]) + end - def conferences - @conferences ||= Conference.in_current_season.order(:name) - end - helper_method :conferences + def conferences + @conferences ||= Conference.in_current_season.order(:name) + end + helper_method :conferences - def teams - all_teams = Team.all.order(:name) - selected_teams = Team.in_current_season.selected.order(:name) - current_season.active? ? selected_teams : all_teams - end - helper_method :teams - - def user_params - params.require(:user).permit( - :github_handle, :twitter_handle, :irc_handle, - :name, :email, :homepage, :location, :bio, - :tshirt_size, :tshirt_cut, :postal_address, :timezone, - :country, - :hide_email, - :is_company, :company_name, :company_info, - :application_about, :application_motivation, :application_gender_identification, :application_age, - :application_coding_level, :application_community_engagement, :application_language_learning_period, - :application_learning_history, :application_skills, :application_code_samples, - :application_location, :application_minimum_money, :application_money, :application_goals, :application_code_background, - interested_in: [], - roles_attributes: [:id, :name, :team_id, :_destroy] - ) - end + def teams + all_teams = Team.all.order(:name) + selected_teams = Team.in_current_season.selected.order(:name) + current_season.active? ? selected_teams : all_teams + end + helper_method :teams + + def user_params + params.require(:user).permit( + :github_handle, :twitter_handle, :irc_handle, + :name, :email, :homepage, :location, :bio, + :tshirt_size, :tshirt_cut, :postal_address, :timezone, + :country, + :hide_email, + :is_company, :company_name, :company_info, + :application_about, :application_motivation, :application_gender_identification, :application_age, + :application_coding_level, :application_community_engagement, :application_language_learning_period, + :application_learning_history, :application_skills, :application_code_samples, + :application_location, :application_minimum_money, :application_money, :application_goals, :application_code_background, + interested_in: [], + roles_attributes: [:id, :name, :team_id, :_destroy] + ) + end end diff --git a/app/exporters/conference_preferences.rb b/app/exporters/conference_preferences.rb index 27f10cd81..2a8c91c21 100644 --- a/app/exporters/conference_preferences.rb +++ b/app/exporters/conference_preferences.rb @@ -8,18 +8,18 @@ def current header = 'Team name', 'Team location', 'Project name', 'Conference primary choice', 'Conference secondary choice', 'We would like to give a LT', 'Comments', 'Terms accepted' max_offer.times do |n| - header << "Conference Offer #{n+1}" - header << "Conference Offer #{n+1} accepted" + header << "Conference Offer #{n + 1}" + header << "Conference Offer #{n + 1} accepted" end generate(preferences, *header) do |cp| - team_preferences = [cp.team&.name, cp.team&.students_location, cp.team&.project_name, cp.first_conference&.name, cp.second_conference&.name, cp.lightning_talk, cp.comment, cp.terms_accepted?] - cp.team&.conference_attendances&.each do |ca| - team_preferences << ca.conference.name - team_preferences << ca.attendance - end - team_preferences + team_preferences = [cp.team&.name, cp.team&.students_location, cp.team&.project_name, cp.first_conference&.name, cp.second_conference&.name, cp.lightning_talk, cp.comment, cp.terms_accepted?] + cp.team&.conference_attendances&.each do |ca| + team_preferences << ca.conference.name + team_preferences << ca.attendance end + team_preferences end end end +end diff --git a/app/helpers/application_drafts_helper.rb b/app/helpers/application_drafts_helper.rb index 0f79308f9..5d2a3395d 100644 --- a/app/helpers/application_drafts_helper.rb +++ b/app/helpers/application_drafts_helper.rb @@ -72,6 +72,7 @@ def team_tab_errors(draft) end private + def tab_errors(draft, fields) count = draft.errors.keys.map { |field| field if fields.include? field }.compact.count if count > 0 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f16d9a4b2..62d76e48b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -140,18 +140,16 @@ def status_for(team, member, role_name) role = team.roles.find { |role| role.user == member} if role && role.confirmed? content_tag :span, 'Confirmed', class: 'label label-default' + elsif current_user == member + link_to 'Confirm', confirm_role_path((role.confirmation_token || 'confirmation-token-missing')), method: :put, class: 'btn btn-sm btn-success' else - if current_user == member - link_to 'Confirm', confirm_role_path((role.confirmation_token || 'confirmation-token-missing')), method: :put, class: 'btn btn-sm btn-success' - else - content_tag :span, 'Not confirmed yet', class: 'label label-default' - end + content_tag :span, 'Not confirmed yet', class: 'label label-default' end end end def link_to_team_member(member) - content_tag(:li, :class => :user) do + content_tag(:li, class: :user) do avatar_url(member, size: 40) + link_to(member.name_or_handle, member) end @@ -211,4 +209,4 @@ def time_for_user(user) def list_all_timezones TIMEZONES end -end \ No newline at end of file +end diff --git a/app/helpers/authentication/active_record_helpers.rb b/app/helpers/authentication/active_record_helpers.rb index 0eab0b679..b9eb50930 100644 --- a/app/helpers/authentication/active_record_helpers.rb +++ b/app/helpers/authentication/active_record_helpers.rb @@ -21,7 +21,7 @@ def find_for_github_oauth(auth) end def create_for_github_oauth(auth) - update_user(new(), auth) + update_user(new, auth) end def update_user(user, auth) diff --git a/app/helpers/conference_attendances_helper.rb b/app/helpers/conference_attendances_helper.rb index 4f6687966..34060bb32 100644 --- a/app/helpers/conference_attendances_helper.rb +++ b/app/helpers/conference_attendances_helper.rb @@ -2,17 +2,17 @@ module ConferenceAttendancesHelper def show_attendance(attendance) label_class = case attendance - when true - 'label-success' - when false - 'label-warning' - end + when true + 'label-success' + when false + 'label-warning' + end text_label = case attendance - when true - "I will attend this conference" - when false - "I will not attend this conference" - end + when true + "I will attend this conference" + when false + "I will not attend this conference" + end content_tag :span, text_label, class: "label #{label_class}" end -end \ No newline at end of file +end diff --git a/app/helpers/teams_helper.rb b/app/helpers/teams_helper.rb index 77fab98aa..183a02441 100644 --- a/app/helpers/teams_helper.rb +++ b/app/helpers/teams_helper.rb @@ -8,4 +8,4 @@ def conference_exists_for?(team) conference_preference.second_conference_id ].any? end -end \ No newline at end of file +end diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb index 51aec664c..d9596b4f9 100644 --- a/app/mailers/comment_mailer.rb +++ b/app/mailers/comment_mailer.rb @@ -14,12 +14,12 @@ def email(comment) private - def subject - "[rgsoc-teams] New comment: #{team.name} - #{truncate(comment.text)}" - end + def subject + "[rgsoc-teams] New comment: #{team.name} - #{truncate(comment.text)}" + end - def set(comment) - @team = comment.commentable - @comment = comment - end + def set(comment) + @team = comment.commentable + @comment = comment + end end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index c7efc2cc9..51d9fbbd4 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -20,8 +20,8 @@ def email(submission) private - def set(submission) - @submission = submission - @mailing = submission.mailing - end + def set(submission) + @submission = submission + @mailing = submission.mailing + end end diff --git a/app/mailers/reminder_mailer.rb b/app/mailers/reminder_mailer.rb index 713a4a5f6..7804399b8 100644 --- a/app/mailers/reminder_mailer.rb +++ b/app/mailers/reminder_mailer.rb @@ -10,7 +10,8 @@ def update_log(team) end private - def subject - "[rgsoc-teams] Reminder: please update your team log" - end + + def subject + "[rgsoc-teams] Reminder: please update your team log" + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index ce691a90f..546a8a75b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -7,7 +7,7 @@ class Ability def initialize(user) user ||= User.new - alias_action :create, :read, :update, :destroy, :to => :crud + alias_action :create, :read, :update, :destroy, to: :crud can :crud, User, id: user.id can :crud, User if user.admin? @@ -63,12 +63,12 @@ def initialize(user) can :crud, Conference if user.admin? || user.current_student? - #todo add mailing controller and view for users in their namespace, where applicable + # todo add mailing controller and view for users in their namespace, where applicable can :read, Mailing do |mailing| mailing.recipient? user end - can :crud, :comments if user.admin? + can :crud, :comments if user.admin? can :read, :users_info if user.admin? || user.supervisor? can :crud, Project do |project| diff --git a/app/models/application.rb b/app/models/application.rb index 4b5cf7a01..2fe3db1d0 100644 --- a/app/models/application.rb +++ b/app/models/application.rb @@ -31,9 +31,9 @@ def self.data_label(key) end def data - ApplicationData.new(self.application_data) + ApplicationData.new(application_data) end - + def self.rateable joins("LEFT JOIN projects p1 ON p1.id::text = applications.application_data -> 'project1_id'") .joins("LEFT JOIN projects p2 ON p2.id::text = applications.application_data -> 'project2_id'") diff --git a/app/models/application_draft.rb b/app/models/application_draft.rb index e5a5c3a32..2c1260a44 100644 --- a/app/models/application_draft.rb +++ b/app/models/application_draft.rb @@ -122,8 +122,8 @@ def ready? valid?(:apply) end - aasm :column => :state, :no_direct_assignment => true do - state :draft, :initial => true + aasm column: :state, no_direct_assignment: true do + state :draft, initial: true state :applied event :submit_application do @@ -132,7 +132,7 @@ def ready? CreatesApplicationFromDraft.new(self).save end - transitions :from => :draft, :to => :applied, :guard => :ready? + transitions from: :draft, to: :applied, guard: :ready? end end @@ -167,6 +167,6 @@ def students_confirmed? end def clean_up_heard_about_it - self.heard_about_it = self.heard_about_it.reject(&:empty?) + self.heard_about_it = heard_about_it.reject(&:empty?) end end diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 08fc93627..1e5d7f2b4 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -96,6 +96,6 @@ def fields end def attributes - fields.inject({}) { |result, field| result[field] = self.send(field); result } + fields.inject({}) { |result, field| result[field] = send(field); result } end end diff --git a/app/models/concerns/rateable.rb b/app/models/concerns/rateable.rb index ee23470d2..fbe1cc4df 100644 --- a/app/models/concerns/rateable.rb +++ b/app/models/concerns/rateable.rb @@ -16,7 +16,7 @@ def median_points if rating_points.size % 2 == 1 rating_points[m_pos].round(2) else - mean(rating_points[m_pos-1..m_pos]).round(2) + mean(rating_points[m_pos - 1..m_pos]).round(2) end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 9c2521890..7967e91d8 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -11,8 +11,8 @@ class Conference < ActiveRecord::Base include HasSeason has_many :conference_attendances, dependent: :destroy - has_many :first_choice_conference_preferences, :class_name => 'ConferencePreference', :foreign_key => 'first_conference_id' - has_many :second_choice_conference_preferences, :class_name => 'ConferencePreference', :foreign_key => 'second_conference_id' + has_many :first_choice_conference_preferences, class_name: 'ConferencePreference', foreign_key: 'first_conference_id' + has_many :second_choice_conference_preferences, class_name: 'ConferencePreference', foreign_key: 'second_conference_id' has_many :attendees, through: :first_choice_conference_preferences, source: :team has_many :attendees, through: :second_choice_conference_preferences, source: :team @@ -36,4 +36,4 @@ def tickets_left confirmed_attendances = conference_preference.select { |conference_preference| conference_preference.confirmed } tickets.to_i - confirmed_attendances.size end -end \ No newline at end of file +end diff --git a/app/models/conference/importer.rb b/app/models/conference/importer.rb index 50819a3c2..4cef350d1 100644 --- a/app/models/conference/importer.rb +++ b/app/models/conference/importer.rb @@ -44,7 +44,7 @@ def conferences_count def fetch_season_id(uid) # uid format : 2017001 - year = uid.to_s[0,4] + year = uid.to_s[0, 4] Season.find_or_create_by!(name: year).id end diff --git a/app/models/conference_preference.rb b/app/models/conference_preference.rb index 1373aec62..9e0515e65 100644 --- a/app/models/conference_preference.rb +++ b/app/models/conference_preference.rb @@ -16,16 +16,17 @@ def has_preference? end def terms_accepted? - self.terms_of_travel && self.terms_of_ticket + terms_of_travel && terms_of_ticket end private - def conference_exists? - first_conference_id.present? || second_conference_id.present? - end - def change_status_terms - self.terms_of_travel = false - self.terms_of_ticket = false - end -end \ No newline at end of file + def conference_exists? + first_conference_id.present? || second_conference_id.present? + end + + def change_status_terms + self.terms_of_travel = false + self.terms_of_ticket = false + end +end diff --git a/app/models/date_range.rb b/app/models/date_range.rb index deeec1d5a..52618bedb 100644 --- a/app/models/date_range.rb +++ b/app/models/date_range.rb @@ -3,14 +3,14 @@ class DateRange # Validation is supposed to be in input (e.g. Conference.rb), but # with the new Importer for adding conferences, the presence validation # of the dates is removed. - + ELEMENTS = "%-d %b %Y" # "1 juli 2017" - + def initialize(start_date:, end_date:) @start_date = start_date @end_date = end_date end - + # Accepts dates # Returns a string with one or more dates, with # the following formats: @@ -18,19 +18,19 @@ def initialize(start_date:, end_date:) # 31 Dec 2017 - 5 Jan 2018 or 1 Dec 2017 - 12 Dec 2018 def to_s return last_day if start_date == end_date - + format = ELEMENTS format = format.chomp(' %Y') if start_date.year == end_date.year format = format.chomp(' %b') if start_date.month == end_date.month first_day = start_date.strftime(format) first_day + ' - ' + last_day end - + private - + attr_reader :start_date, :end_date - + def last_day end_date&.strftime(ELEMENTS) || "TBA" end -end \ No newline at end of file +end diff --git a/app/models/note.rb b/app/models/note.rb index 0ff2672c0..c6f90a1c5 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -4,4 +4,4 @@ def self.notepad(user) Note.find_or_create_by(user_id: user.id) end -end \ No newline at end of file +end diff --git a/app/models/rating.rb b/app/models/rating.rb index dbaf998b8..d72714a75 100644 --- a/app/models/rating.rb +++ b/app/models/rating.rb @@ -138,7 +138,7 @@ def woman? # public: The weighted sum of the points that the reviewer gave. def points weighted_points = FIELDS.map do |name, rating_criterium| - rating_criterium.weighted_points(self.send(name)) + rating_criterium.weighted_points(send(name)) end weighted_points.sum @@ -149,7 +149,7 @@ def points def set_data new_data = ActiveSupport::HashWithIndifferentAccess.new FIELDS.keys.each do |name| - points = self.send(name) + points = send(name) new_data = new_data.merge({ name => points }) end diff --git a/app/models/rating/table.rb b/app/models/rating/table.rb index e451f1e47..0910c3772 100644 --- a/app/models/rating/table.rb +++ b/app/models/rating/table.rb @@ -24,17 +24,17 @@ def initialize(applications:, options: {}) def sort_order case options[:order] when :team_name - ->(a,b) { a.team_name <=> b.team_name } + ->(a, b) { a.team_name <=> b.team_name } when :total_likes - ->(a,b) { b.total_likes <=> a.total_likes } + ->(a, b) { b.total_likes <=> a.total_likes } when :total_picks - ->(a,b) { b.total_picks <=> a.total_picks } + ->(a, b) { b.total_picks <=> a.total_picks } when :average_points - ->(a,b) { b.average_points <=> a.average_points } + ->(a, b) { b.average_points <=> a.average_points } when :median_points - ->(a,b) { b.median_points <=> a.median_points } + ->(a, b) { b.median_points <=> a.median_points } else - ->(a,b) { a.id <=> b.id } + ->(a, b) { a.id <=> b.id } end end diff --git a/app/models/rating_criterium.rb b/app/models/rating_criterium.rb index 2efd5e48e..0a8a483f9 100644 --- a/app/models/rating_criterium.rb +++ b/app/models/rating_criterium.rb @@ -32,4 +32,4 @@ def point_options def weighted_points(points) (points.to_f || 0) * @weight end -end \ No newline at end of file +end diff --git a/app/models/role.rb b/app/models/role.rb index 851d9cc32..b5fdb19a4 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -33,7 +33,7 @@ def includes?(role_name) end aasm column: :state, no_direct_assignment: true do - state :pending, :initial => true + state :pending, initial: true state :confirmed event :confirm do diff --git a/app/models/season.rb b/app/models/season.rb index 64420332a..c393f1a45 100644 --- a/app/models/season.rb +++ b/app/models/season.rb @@ -11,7 +11,7 @@ class Season < ActiveRecord::Base APPL_CLOSE = [3, 31] APPL_LETTER = [5, 1] PROJECTS_OPEN = [12, 1] - PROJECTS_CLOSE= [2, 1] + PROJECTS_CLOSE = [2, 1] class << self def current @@ -19,7 +19,7 @@ def current end def succ - find_or_create_by(name: (Date.today.year+1).to_s) + find_or_create_by(name: (Date.today.year + 1).to_s) end # Project proposals open early. This predicate tells us if @@ -42,7 +42,7 @@ def all_years end def application_period? - Time.now.utc.between? applications_open_at, applications_close_at + Time.now.utc.between? applications_open_at, applications_close_at end def applications_open? @@ -76,7 +76,7 @@ def set_application_dates self.applications_open_at ||= Time.utc(year, *APPL_OPEN) self.applications_close_at ||= Time.utc(year, *APPL_CLOSE) self.acceptance_notification_at ||= Time.utc(year, *APPL_LETTER) # 1 May - self.project_proposals_open_at ||= Time.utc(year.to_i-1, *PROJECTS_OPEN) + self.project_proposals_open_at ||= Time.utc(year.to_i - 1, *PROJECTS_OPEN) self.project_proposals_close_at ||= Time.utc(year, *PROJECTS_CLOSE) self.acceptance_notification_at = acceptance_notification_at.utc.end_of_day self.project_proposals_open_at = project_proposals_open_at.beginning_of_day diff --git a/app/models/season/phase_switcher.rb b/app/models/season/phase_switcher.rb index f6330a1b8..e69a103a7 100644 --- a/app/models/season/phase_switcher.rb +++ b/app/models/season/phase_switcher.rb @@ -11,7 +11,7 @@ class Season::PhaseSwitcher def self.destined(phase) raise ArgumentError.new("#{phase} is not a valid phase") unless phase.in? PHASES - self.send(phase) + send(phase) end private @@ -61,8 +61,8 @@ def self.back_to_reality applications_open_at: Time.utc(this_year, *Season::APPL_OPEN), applications_close_at: Time.utc(this_year, *Season::APPL_CLOSE), acceptance_notification_at: Time.utc(this_year, *Season::APPL_LETTER), - project_proposals_open_at: Time.utc(this_year-1, *Season::PROJECTS_OPEN), - project_proposals_close_at: Time.utc(this_year, *Season::PROJECTS_CLOSE), + project_proposals_open_at: Time.utc(this_year - 1, *Season::PROJECTS_OPEN), + project_proposals_close_at: Time.utc(this_year, *Season::PROJECTS_CLOSE) ) end -end \ No newline at end of file +end diff --git a/app/models/student.rb b/app/models/student.rb index fb6c201ab..bbd5b5633 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -43,10 +43,10 @@ def current_team def current_drafts @current_drafts ||= if current_team - current_team.application_drafts.in_current_season - else - [] - end + current_team.application_drafts.in_current_season + else + [] + end end def current_draft diff --git a/app/models/team_performance.rb b/app/models/team_performance.rb index a8bc89f3a..e285fcd22 100644 --- a/app/models/team_performance.rb +++ b/app/models/team_performance.rb @@ -34,7 +34,7 @@ def evaluation def self.buffer_days? # the first few days, plus the days before and after the coding season - Time.now < Season.current.starts_at+2.days || !Season.current.started? || Time.now > Season.current.ends_at+2.days + Time.now < Season.current.starts_at + 2.days || !Season.current.started? || Time.now > Season.current.ends_at + 2.days end def comments_score @@ -42,11 +42,11 @@ def comments_score if !self.class.buffer_days? if @team.comments.empty? @score += 3 - elsif latest_comment.created_at <= Time.now-5.days + elsif latest_comment.created_at <= Time.now - 5.days @score += 2 - elsif latest_comment.created_at <= Time.now-2.days + elsif latest_comment.created_at <= Time.now - 2.days @score += 1 - elsif latest_comment.created_at > Time.now-2.days + elsif latest_comment.created_at > Time.now - 2.days @score += 0 else @score += 1 @@ -58,11 +58,11 @@ def activity_score if !self.class.buffer_days? if @team.activities.empty? @score += 3 - elsif @team.last_activity.created_at <= Time.now-5.days + elsif @team.last_activity.created_at <= Time.now - 5.days @score += 2 - elsif @team.last_activity.created_at <= Time.now-3.days + elsif @team.last_activity.created_at <= Time.now - 3.days @score += 1 - elsif @team.last_activity.created_at > Time.now-3.days + elsif @team.last_activity.created_at > Time.now - 3.days @score += 0 else @score += 1 @@ -70,4 +70,4 @@ def activity_score end end -end \ No newline at end of file +end diff --git a/app/models/todo.rb b/app/models/todo.rb index b90c02e62..581dc1586 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -33,6 +33,6 @@ def sign_offs? end def validate_number_of_reviewers - errors.add(:user, "too many reviewers") if self.application.todos.size > 3 + errors.add(:user, "too many reviewers") if application.todos.size > 3 end end diff --git a/config.ru b/config.ru index fe8b90584..50ac79b67 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run RgsocTeams::Application diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 97d34efec..4ec674b1a 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -7,7 +7,7 @@ # OmniAuth.config.full_host = "http://localhost:3000" # wat, keeps missing the port for the redirect_uri without this Devise.setup do |config| - config.omniauth :github, GITHUB_APP_ID, GITHUB_APP_SECRET, :scope => 'user:email' + config.omniauth :github, GITHUB_APP_ID, GITHUB_APP_SECRET, scope: 'user:email' config.secret_key = ENV['DEVISE_SECRET'] || 'adc96b68ccb1630810f073823ea5f942df52649385b04e18223b845dd66c7f48ca9641ca2ed456ae4755fbb24f7b08e2ceaeaa21cac8e0aead38a9f60e831392' # ==> Mailer Configuration diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb index 0db8abd75..713c988eb 100644 --- a/config/initializers/kaminari_config.rb +++ b/config/initializers/kaminari_config.rb @@ -1,5 +1,5 @@ Kaminari.configure do |config| - config.default_per_page = 25 + config.default_per_page = 25 # config.max_per_page = nil # config.window = 4 # config.outer_window = 0 diff --git a/config/routes.rb b/config/routes.rb index 8f5bed7f5..7cdf63092 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,7 +96,7 @@ end namespace :students do - resources :status_updates, :except => [:new] do + resources :status_updates, except: [:new] do post 'preview', on: :collection end end diff --git a/db/migrate/20170707145338_remove_columns_from_attendance.rb b/db/migrate/20170707145338_remove_columns_from_attendance.rb index 6515b2cab..2cfb0136c 100644 --- a/db/migrate/20170707145338_remove_columns_from_attendance.rb +++ b/db/migrate/20170707145338_remove_columns_from_attendance.rb @@ -1,11 +1,11 @@ class RemoveColumnsFromAttendance < ActiveRecord::Migration[5.1] def up - remove_column :attendances, :conference_id - remove_column :attendances, :user_id + remove_column :attendances, :conference_id + remove_column :attendances, :user_id end def down - add_column :attendances, :conference_id, :integer - add_column :attendances, :user_id, :integer + add_column :attendances, :conference_id, :integer + add_column :attendances, :user_id, :integer end end diff --git a/db/migrate/20170731173902_add_columns_into_conference_preferences.rb b/db/migrate/20170731173902_add_columns_into_conference_preferences.rb index 0380aae7f..99885b083 100644 --- a/db/migrate/20170731173902_add_columns_into_conference_preferences.rb +++ b/db/migrate/20170731173902_add_columns_into_conference_preferences.rb @@ -8,4 +8,4 @@ def self.down remove_column :conference_preferences, :comment, :text remove_column :conference_preferences, :lightning_talk, :boolean, default: false end -end \ No newline at end of file +end diff --git a/db/migrate/20170810172601_add_columns_into_conference_preference.rb b/db/migrate/20170810172601_add_columns_into_conference_preference.rb index fe1145dda..e8a054b6d 100644 --- a/db/migrate/20170810172601_add_columns_into_conference_preference.rb +++ b/db/migrate/20170810172601_add_columns_into_conference_preference.rb @@ -8,4 +8,4 @@ def self.down remove_column :conference_preferences, :terms_of_ticket remove_column :conference_preferences, :terms_of_travel end -end \ No newline at end of file +end diff --git a/db/seeds.rb b/db/seeds.rb index ea5cd9d5a..59864cd59 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ # Teams FactoryGirl.create_list(:team, 5, :in_current_season, kind: "sponsored") FactoryGirl.create(:team, :in_current_season, kind: "voluntary") -FactoryGirl.create(:team, :in_current_season) #not accepted +FactoryGirl.create(:team, :in_current_season) # not accepted FactoryGirl.create(:team, :last_season, kind: "sponsored") FactoryGirl.create(:team, :last_season, kind: "voluntary") @@ -25,7 +25,7 @@ FactoryGirl.create(:application_draft) FactoryGirl.create(:application_draft, :appliable) -FactoryGirl.create(:project, :in_current_season) #proposed +FactoryGirl.create(:project, :in_current_season) # proposed FactoryGirl.create_list(:project, 3, :accepted, :in_current_season) FactoryGirl.create(:project, :rejected, :in_current_season) @@ -38,9 +38,9 @@ starts_on: random_date, ends_on: random_date + rand(2.days), lightningtalkslots: rand < 0.5, - tickets: [2,4,6].sample, + tickets: [2, 4, 6].sample, accomodation: 2, flights: 0, - round: [1,2].sample + round: [1, 2].sample ) end diff --git a/lib/confs/conf.rb b/lib/confs/conf.rb index 547c2fe31..5a9ba28ca 100644 --- a/lib/confs/conf.rb +++ b/lib/confs/conf.rb @@ -30,7 +30,7 @@ def to_row [popularity, name, tickets, flights] end - def <=> (other) + def <=>(other) name <=> other.name end end diff --git a/lib/confs/confs.rb b/lib/confs/confs.rb index 2adf964d5..10917f26c 100644 --- a/lib/confs/confs.rb +++ b/lib/confs/confs.rb @@ -28,8 +28,8 @@ def total_tickets private - def cmp(attr, lft, rgt) - order = lft.send(attr) <=> rgt.send(attr) - order unless order == 0 - end + def cmp(attr, lft, rgt) + order = lft.send(attr) <=> rgt.send(attr) + order unless order == 0 + end end diff --git a/lib/confs/raffle.rb b/lib/confs/raffle.rb index 3595514a1..7110299d4 100644 --- a/lib/confs/raffle.rb +++ b/lib/confs/raffle.rb @@ -34,46 +34,46 @@ def run private - def run? - confs.any? { |confs| confs.tickets? } && runs < 100 - end + def run? + confs.any? { |confs| confs.tickets? } && runs < 100 + end - def available_confs - confs.select { |conf| conf.tickets? } - end + def available_confs + confs.select { |conf| conf.tickets? } + end # Tries to pick a team for the given conf. If there are at least two # tickets available then it tries to find teams who has applied and where # none of the student who has won during this raffle already. Then picks # one of these teams randomly. - def pick_team(conf) - return unless conf.tickets >= 2 - teams = apps.select_teams_by(conf_name: conf.name) - teams = teams.reject { |team| team.any? { |app| winner?(app) } } - if team = teams.shuffle.first - team.each { |app| win(app) } - end + def pick_team(conf) + return unless conf.tickets >= 2 + teams = apps.select_teams_by(conf_name: conf.name) + teams = teams.reject { |team| team.any? { |app| winner?(app) } } + if team = teams.shuffle.first + team.each { |app| win(app) } end + end # Tries to pick a student for the given conf. If there's at least one # ticket avaialbe then it tries to find students who have not won during # this raffle already. Then picks one of these students randomly. - def pick_student(conf) - return unless conf.tickets? - apps = self.apps.select_by(conf_name: conf.name) - apps = apps.reject { |app| winner?(app) } - if app = apps.shuffle.first - win(app) - end + def pick_student(conf) + return unless conf.tickets? + apps = self.apps.select_by(conf_name: conf.name) + apps = apps.reject { |app| winner?(app) } + if app = apps.shuffle.first + win(app) end + end - def winner?(app) - winners.map(&:name).include?(app.name) - end + def winner?(app) + winners.map(&:name).include?(app.name) + end - def win(app) - apps.remove(app) - app.conf.attend(app) - winners << app - end + def win(app) + apps.remove(app) + app.conf.attend(app) + winners << app + end end diff --git a/lib/confs/table.rb b/lib/confs/table.rb index 79e7f118a..2c22f47ce 100644 --- a/lib/confs/table.rb +++ b/lib/confs/table.rb @@ -37,11 +37,11 @@ def to_s private - def format_row(row) - Row.new(self, row).to_s - end + def format_row(row) + Row.new(self, row).to_s + end - def separator - Row.new(self, rows.first.each_with_index.map { |cell, ix| '-' * width(ix) }).to_s('+') - end + def separator + Row.new(self, rows.first.each_with_index.map { |cell, ix| '-' * width(ix) }).to_s('+') + end end diff --git a/lib/feed.rb b/lib/feed.rb index 2a38a86cc..e3de0d57b 100644 --- a/lib/feed.rb +++ b/lib/feed.rb @@ -33,37 +33,37 @@ def update private - def discover_title - title = Discovery.new(source.url, logger: logger).title - logger.info "discovered title for #{source.url}: #{title}" - title - end + def discover_title + title = Discovery.new(source.url, logger: logger).title + logger.info "discovered title for #{source.url}: #{title}" + title + end - def discover_feed_url - urls = Discovery.new(source.url, logger: logger).feed_urls - url = urls.reject { |url| url =~ /comment/ }.first - logger.info "discovered feed url for #{source.url}: #{url}" if url - url || source.url - end + def discover_feed_url + urls = Discovery.new(source.url, logger: logger).feed_urls + url = urls.reject { |url| url =~ /comment/ }.first + logger.info "discovered feed url for #{source.url}: #{url}" if url + url || source.url + end - def update_entries - parse.entries.each do |data| - item = Item.new(source.url, source.team_id, data) - raise "can not find guid for item in source #{source.feed_url}" unless item.guid - # logger.info "processing item #{item.guid}: #{item.title}" - record = Activity.where(:guid => item.guid).first - attrs = item.attrs.merge(img_url: record.try(:img_url) || Image.new(item.url, logger: logger).store) - record ? record.update_attributes!(attrs) : Activity.create!(attrs) - end - rescue => e - logger.error "Could not update entries: #{e.message}" - nil + def update_entries + parse.entries.each do |data| + item = Item.new(source.url, source.team_id, data) + raise "can not find guid for item in source #{source.feed_url}" unless item.guid + # logger.info "processing item #{item.guid}: #{item.title}" + record = Activity.where(guid: item.guid).first + attrs = item.attrs.merge(img_url: record.try(:img_url) || Image.new(item.url, logger: logger).store) + record ? record.update_attributes!(attrs) : Activity.create!(attrs) end + rescue => e + logger.error "Could not update entries: #{e.message}" + nil + end - def parse - logger.info "Feeds: going to fetch #{source.feed_url}" - data = Feedjira::Feed.fetch_and_parse(source.feed_url) - logger.info "this does not look like a valid feed" unless data.respond_to?(:entries) - data - end + def parse + logger.info "Feeds: going to fetch #{source.feed_url}" + data = Feedjira::Feed.fetch_and_parse(source.feed_url) + logger.info "this does not look like a valid feed" unless data.respond_to?(:entries) + data + end end diff --git a/lib/feed/discovery.rb b/lib/feed/discovery.rb index 47793675d..5d438792c 100644 --- a/lib/feed/discovery.rb +++ b/lib/feed/discovery.rb @@ -19,26 +19,26 @@ def feed_urls private - def html - open(url).read - end + def html + open(url).read + end - def expand(url) - url =~ /^http/ ? url : base_url + url - end + def expand(url) + url =~ /^http/ ? url : base_url + url + end - def base_url - (url =~ %r(^(https?://[^/]+)) && $1).to_s - end + def base_url + (url =~ %r(^(https?://[^/]+)) && $1).to_s + end - def urls - tags.map { |tag| tag.match(/.*href=['"](.*?)['"].*/) && $1 }.compact - end + def urls + tags.map { |tag| tag.match(/.*href=['"](.*?)['"].*/) && $1 }.compact + end - def tags - html.scan(/(<(a|link)[^>]*>)/).flatten.select do |tag| - tag =~ /.*type=['"]application\/(rss|atom)\+xml['"].*/ - end + def tags + html.scan(/(<(a|link)[^>]*>)/).flatten.select do |tag| + tag =~ /.*type=['"]application\/(rss|atom)\+xml['"].*/ end + end end end diff --git a/lib/github/user.rb b/lib/github/user.rb index 70965ecbc..9ced2fcc4 100644 --- a/lib/github/user.rb +++ b/lib/github/user.rb @@ -29,14 +29,14 @@ def send_devise_notification(notification, *args) private - def data - @data ||= gh["users/#{handle}"] - end + def data + @data ||= gh["users/#{handle}"] + end - def gh - @gh ||= options[:gh] || GH::Stack.build do - use GH::Normalizer - end + def gh + @gh ||= options[:gh] || GH::Stack.build do + use GH::Normalizer end + end end end diff --git a/lib/selection/distance.rb b/lib/selection/distance.rb index a346db8b7..f60fad9cc 100644 --- a/lib/selection/distance.rb +++ b/lib/selection/distance.rb @@ -25,9 +25,9 @@ def to_km def haversine_distance - a = Math.sin(delta_lat/2)**2 + - Math.cos(from_lat) * Math.cos(to_lat) * Math.sin(delta_lng/2)**2 - c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)) + a = Math.sin(delta_lat / 2)**2 + + Math.cos(from_lat) * Math.cos(to_lat) * Math.sin(delta_lng / 2)**2 + c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) (c * RADIUS_OF_EARTH_IN_M).round end diff --git a/lib/selection/refinements.rb b/lib/selection/refinements.rb index 493150eff..d20ae1e97 100644 --- a/lib/selection/refinements.rb +++ b/lib/selection/refinements.rb @@ -3,7 +3,7 @@ module Refinements module StringMathExtensions refine String do def to_rad - self.to_f * Math::PI / 180 + to_f * Math::PI / 180 end end end diff --git a/lib/tasks/activity.rake b/lib/tasks/activity.rake index 1b56d72f2..8ea193c72 100644 --- a/lib/tasks/activity.rake +++ b/lib/tasks/activity.rake @@ -5,4 +5,4 @@ namespace :activity do task update: :environment do Feed.update_all end -end \ No newline at end of file +end diff --git a/lib/tasks/teams.rake b/lib/tasks/teams.rake index bea889189..39b712909 100644 --- a/lib/tasks/teams.rake +++ b/lib/tasks/teams.rake @@ -10,4 +10,4 @@ namespace :teams do end end end -end \ No newline at end of file +end diff --git a/spec/controllers/community_controller_spec.rb b/spec/controllers/community_controller_spec.rb index 1f4f2274a..612e4a543 100644 --- a/spec/controllers/community_controller_spec.rb +++ b/spec/controllers/community_controller_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' RSpec.describe CommunityController do - render_views + render_views let(:valid_attributes) { build(:user).attributes.except('github_id', 'avatar_url', *User.immutable_attributes.map(&:to_s)) } describe "GET index" do it "assigns all users that have any roles assigned as @users" do - student = FactoryGirl.create(:student) + student = FactoryGirl.create(:student) coach = FactoryGirl.create(:coach) get :index expect(assigns(:users).to_a).to include(coach) && include(student) @@ -64,4 +64,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/controllers/conference_attendances_controller_spec.rb b/spec/controllers/conference_attendances_controller_spec.rb index 7c8bd140f..977a4a736 100644 --- a/spec/controllers/conference_attendances_controller_spec.rb +++ b/spec/controllers/conference_attendances_controller_spec.rb @@ -4,7 +4,7 @@ let(:team) { FactoryGirl.create(:team, :in_current_season) } let(:student) { FactoryGirl.create(:student, team: team)} let(:attendance) { FactoryGirl.create(:conference_attendance, team: team )} - + before do sign_in student end @@ -12,7 +12,7 @@ describe 'PUT update' do it "can update her team's attendances" do put :update, params: { id: attendance.id, conference_attendance: { attendance: true }} - expect(attendance.reload.attendance).to be_truthy + expect(attendance.reload.attendance).to be_truthy end end end diff --git a/spec/controllers/conferences_controller_spec.rb b/spec/controllers/conferences_controller_spec.rb index a02c3922b..5b2791179 100644 --- a/spec/controllers/conferences_controller_spec.rb +++ b/spec/controllers/conferences_controller_spec.rb @@ -4,7 +4,7 @@ render_views describe 'GET index' do - let(:last_season) { Season.create name: Date.today.year-1 } + let(:last_season) { Season.create name: Date.today.year - 1 } let!(:current_conference) { create :conference, :in_current_season } let!(:last_years_conference) { create :conference, season: last_season } @@ -34,7 +34,7 @@ context 'student logged in' do let!(:student) { FactoryGirl.create(:student) } let(:team) { student.student_team } - let(:params) { { name: 'name', country: 'country', region: 'region', location: 'location', city: 'city', season_id:'1', url: 'www.conference.com' } } + let(:params) { { name: 'name', country: 'country', region: 'region', location: 'location', city: 'city', season_id: '1', url: 'www.conference.com' } } before :each do sign_in student diff --git a/spec/controllers/orga/projects_controller_spec.rb b/spec/controllers/orga/projects_controller_spec.rb index 284ef9d57..3b589d68a 100644 --- a/spec/controllers/orga/projects_controller_spec.rb +++ b/spec/controllers/orga/projects_controller_spec.rb @@ -18,7 +18,7 @@ end end - + describe 'PUT start_review' do it 'start review before accept or reject a project' do expect { put :start_review, params: { id: project.to_param }}. diff --git a/spec/controllers/orga/teams_controller_spec.rb b/spec/controllers/orga/teams_controller_spec.rb index ab3dc7d73..7bb3aad94 100644 --- a/spec/controllers/orga/teams_controller_spec.rb +++ b/spec/controllers/orga/teams_controller_spec.rb @@ -118,8 +118,8 @@ let(:offer) { FactoryGirl.create(:conference_attendance) } let(:team) { offer.team } let!(:team_params) do - build(:team).attributes.merge(:conference_attendances_attributes=>{ - '0'=>{ + build(:team).attributes.merge(conference_attendances_attributes: { + '0' => { conference_id: offer.conference.id, orga_comment: "commment" } }) diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 098edb2fd..7eba75b10 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -48,7 +48,7 @@ end it 'requires a login' do - expect { get :new }.to \ + expect { get :new }.to \ change { session[:previous_url_login_required] } expect(response).to be_success expect(response.body).to match user_github_omniauth_authorize_path diff --git a/spec/controllers/sources_controller_spec.rb b/spec/controllers/sources_controller_spec.rb index c3d058322..44681ea90 100644 --- a/spec/controllers/sources_controller_spec.rb +++ b/spec/controllers/sources_controller_spec.rb @@ -148,7 +148,7 @@ let!(:params) { { team_id: team.to_param, id: source.to_param } } describe "on their own team" do - let!(:role) { create(:role, name: 'student', team: team, user: user) } + let!(:role) { create(:role, name: 'student', team: team, user: user) } it "destroys the requested source" do expect { delete :destroy, params: params }.to change(Source, :count).by(-1) diff --git a/spec/controllers/students_controller_spec.rb b/spec/controllers/students_controller_spec.rb index c71bb43a6..f7105ea1f 100644 --- a/spec/controllers/students_controller_spec.rb +++ b/spec/controllers/students_controller_spec.rb @@ -5,12 +5,12 @@ describe 'GET index' do let!(:student) { create(:student_role).user } - + it 'returns json representation of user with student role' do get :index, format: :json expect(assigns(:students)).to eq [student] end end - -end \ No newline at end of file + +end diff --git a/spec/controllers/supervisor/base_controller_spec.rb b/spec/controllers/supervisor/base_controller_spec.rb deleted file mode 100644 index 94fd13502..000000000 --- a/spec/controllers/supervisor/base_controller_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe Supervisor::BaseController do - describe 'access for supervisors only', type: :controller do - let(:valid_session) { {} } - let(:user) { FactoryGirl.create(:user) } - let(:team) { FactoryGirl.create(:team) } - - context "with team's supervisor logged in" do - render_views - before do - user.roles.create(name: 'supervisor', team: team) - sign_in user - end - end - end -end diff --git a/spec/controllers/supervisor/dashboard_controller_spec.rb b/spec/controllers/supervisor/dashboard_controller_spec.rb index 50d946bc0..c6f63299c 100644 --- a/spec/controllers/supervisor/dashboard_controller_spec.rb +++ b/spec/controllers/supervisor/dashboard_controller_spec.rb @@ -10,4 +10,4 @@ expect(get('/supervisor')).to route_to('supervisor/dashboard#index') end end -end \ No newline at end of file +end diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index 6e161e5ce..36f63c629 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -18,7 +18,7 @@ describe "GET index" do context 'before acceptance letters are sent' do - let(:last_season) { Season.create name: Date.today.year-1 } + let(:last_season) { Season.create name: Date.today.year - 1 } let!(:invisble_team) { create :team, :in_current_season, kind: nil, invisible: true } let!(:unaccepted_team) { create :team, :in_current_season, kind: nil} let!(:last_years_team) { create :team, kind: 'sponsored', season: last_season } @@ -60,7 +60,7 @@ end context 'after acceptance letters have been sent' do - let(:last_season) { Season.create name: Date.today.year-1 } + let(:last_season) { Season.create name: Date.today.year - 1 } let!(:voluntary_team) { create :team, :in_current_season, kind: 'voluntary' } let!(:sponsored_team) { create :team, :in_current_season, kind: 'sponsored' } let!(:unaccepted_team) { create :team, :in_current_season, kind: nil} @@ -218,7 +218,7 @@ let(:conference_1) { FactoryGirl.create(:conference, :in_current_season)} let(:conference_2) { FactoryGirl.create(:conference, :in_current_season)} let(:team_params) do - build(:team).attributes.merge(:conference_preference_attributes=>{ + build(:team).attributes.merge(conference_preference_attributes: { first_conference_id: conference_1.id, second_conference_id: conference_2.id, terms_of_ticket: '1', diff --git a/spec/exporters/applications_spec.rb b/spec/exporters/applications_spec.rb index 850f19307..18174d3f5 100644 --- a/spec/exporters/applications_spec.rb +++ b/spec/exporters/applications_spec.rb @@ -22,7 +22,7 @@ application end - let!(:new_application) { create :application, :in_current_season } + let!(:new_application) { create :application, :in_current_season } describe '#current' do diff --git a/spec/exporters/conference_preferences_spec.rb b/spec/exporters/conference_preferences_spec.rb index 280d247d5..9c2932d89 100644 --- a/spec/exporters/conference_preferences_spec.rb +++ b/spec/exporters/conference_preferences_spec.rb @@ -8,4 +8,4 @@ described_class.current end end -end \ No newline at end of file +end diff --git a/spec/exporters/teams_spec.rb b/spec/exporters/teams_spec.rb index 243a1cbe1..c3749de96 100644 --- a/spec/exporters/teams_spec.rb +++ b/spec/exporters/teams_spec.rb @@ -46,4 +46,3 @@ end end - diff --git a/spec/factories/conference_preferences.rb b/spec/factories/conference_preferences.rb index 1e2abc35d..0584a3dd6 100644 --- a/spec/factories/conference_preferences.rb +++ b/spec/factories/conference_preferences.rb @@ -16,4 +16,4 @@ terms_of_travel '1' end end -end \ No newline at end of file +end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index b2174188f..9068956b0 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -21,7 +21,7 @@ record.accept! end end - + trait :rejected do after(:create) do |record| record.start_review! diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 2feb9ef15..691d96130 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -113,7 +113,7 @@ link_text = "#{conference.name} (#{conference.date_range})" expect(subject).to eql [link_to(link_text, conference)] end - + context 'with location present' do let(:conference) do build_stubbed :conference, location: 'Melée Island, Carribean', starts_on: '2017-03-14', ends_on: '2017-03-17' diff --git a/spec/helpers/teams_helper_spec.rb b/spec/helpers/teams_helper_spec.rb index e9c7d2dcc..54b05eca6 100644 --- a/spec/helpers/teams_helper_spec.rb +++ b/spec/helpers/teams_helper_spec.rb @@ -15,4 +15,4 @@ expect(conference_exists_for?(team_with)).to be true end end -end \ No newline at end of file +end diff --git a/spec/lib/feed_spec.rb b/spec/lib/feed_spec.rb index ce470ee8c..39eaa1b0f 100644 --- a/spec/lib/feed_spec.rb +++ b/spec/lib/feed_spec.rb @@ -11,7 +11,7 @@ # serve the local directory for faraday root = File.expand_path('spec/stubs/feeds') log = WEBrick::Log.new(File.open(File::NULL, 'w')) - @server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root, :AccessLog => [], :Logger => log + @server = WEBrick::HTTPServer.new Port: 8000, DocumentRoot: root, AccessLog: [], Logger: log @thread = Thread.new { @server.start } end diff --git a/spec/lib/selection/distance_spec.rb b/spec/lib/selection/distance_spec.rb index 58866472a..aa2f706ee 100644 --- a/spec/lib/selection/distance_spec.rb +++ b/spec/lib/selection/distance_spec.rb @@ -28,7 +28,7 @@ end context 'when passing blank strings as input data' do - let(:to) { ['', ''] } + let(:to) { ['', ''] } it 'calculates the distance to zero' do expect(subject.to_km).to eq 4711 diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 8948ec987..49945e4bd 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -12,7 +12,7 @@ describe 'she/he is allowed to do everything on her/his account' do it { expect(ability).to be_able_to(:show, user) } - it { expect(ability).not_to be_able_to(:create, User.new) } #this only happens through GitHub + it { expect(ability).not_to be_able_to(:create, User.new) } # this only happens through GitHub it { expect(ability).to be_able_to(:resend_confirmation_instruction, user) } end @@ -175,29 +175,29 @@ let(:user) { FactoryGirl.build(:student)} context 'when the user is an student of another team' do - it { expect(ability).not_to be_able_to(:see_offered_conferences, Team.new()) } + it { expect(ability).not_to be_able_to(:see_offered_conferences, Team.new) } end context 'when the user is a supervisor of another team' do - before do - allow(user).to receive(:supervisor?).and_return(true) - end - it { expect(ability).not_to be_able_to(:see_offered_conferences, Team.new()) } + before do + allow(user).to receive(:supervisor?).and_return(true) + end + it { expect(ability).not_to be_able_to(:see_offered_conferences, Team.new) } end context "when the user is a team's student" do - it { expect(ability).to be_able_to(:see_offered_conferences, Team.new(:students => [user])) } + it { expect(ability).to be_able_to(:see_offered_conferences, Team.new(students: [user])) } end context "when the user is a team's supervisor" do - it { expect(ability).to be_able_to(:see_offered_conferences, Team.new(:supervisors => [user])) } + it { expect(ability).to be_able_to(:see_offered_conferences, Team.new(supervisors: [user])) } end context 'when the user is an admin' do before do allow(user).to receive(:admin?).and_return(true) end - it { expect(ability).to be_able_to(:see_offered_conferences, Team.new()) } + it { expect(ability).to be_able_to(:see_offered_conferences, Team.new) } end end diff --git a/spec/models/conference_attendance_spec.rb b/spec/models/conference_attendance_spec.rb index 1ed721c35..cb29d3d6b 100644 --- a/spec/models/conference_attendance_spec.rb +++ b/spec/models/conference_attendance_spec.rb @@ -3,4 +3,4 @@ describe ConferenceAttendance do it { is_expected.to belong_to(:team) } it { is_expected.to belong_to(:conference) } -end \ No newline at end of file +end diff --git a/spec/models/conference_preference_spec.rb b/spec/models/conference_preference_spec.rb index 2875db919..a33a92734 100644 --- a/spec/models/conference_preference_spec.rb +++ b/spec/models/conference_preference_spec.rb @@ -136,4 +136,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index b37bef41c..a04d19606 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -44,10 +44,10 @@ end end end - + describe '#date_range' do subject { FactoryGirl.build_stubbed(:conference) } - + it 'has a date range' do expect(subject.date_range).to be_a(DateRange) end @@ -56,9 +56,9 @@ describe '#tickets_left' do context 'ticket value defined' do - let(:conference_preference) { FactoryGirl.build(:conference_preference, confirmed: true) } + let(:conference_preference) { FactoryGirl.build(:conference_preference, confirmed: true) } subject { FactoryGirl.build_stubbed(:conference, tickets: 2) } - + it 'subtracts conference preferences' do allow(subject).to receive(:conference_preference).and_return([conference_preference]) left_tickets = subject.tickets - subject.conference_preference.size @@ -68,7 +68,7 @@ context 'tickets value not defined' do subject { FactoryGirl.build_stubbed(:conference, tickets: nil) } - + it 'returns 0' do allow(subject).to receive(:conference_preference).and_return([]) expect(subject.tickets_left).to eq(0) diff --git a/spec/models/date_range_spec.rb b/spec/models/date_range_spec.rb index d5bbe57b5..ebece53d1 100644 --- a/spec/models/date_range_spec.rb +++ b/spec/models/date_range_spec.rb @@ -1,50 +1,50 @@ require 'spec_helper' RSpec.describe DateRange do - + describe '#to_s' do let(:start_date) { Date.parse('2015-12-31') } let(:end_date) { Date.parse('2015-12-31') } - + subject { described_class.new(start_date: start_date, end_date: end_date).to_s } - + context 'depending on date range' do it 'returns a single day' do expect(subject).to eq ('31 Dec 2015') end - + context 'when multiple dates in same month' do let(:start_date) { Date.parse('2015-12-30') } - + it 'returns combined dates' do expect(subject).to eq ('30 - 31 Dec 2015') end end - + context 'when multiple dates in different months' do let(:start_date) { Date.parse('2015-11-30') } let(:end_date) { Date.parse('2015-12-01') } - + it 'displays the year only once' do expect(subject).to eq ('30 Nov - 1 Dec 2015' ) end end - + context 'when multiple dates around New Year' do let(:end_date) { Date.parse('2016-01-01') } - + it 'returns full dates' do expect(subject).to eq ('31 Dec 2015 - 1 Jan 2016') end end - + context 'when same months, different years' do let(:end_date) { Date.parse('2016-12-01') } - + it 'returns full dates' do expect(subject).to eq ('31 Dec 2015 - 1 Dec 2016') end end end end -end \ No newline at end of file +end diff --git a/spec/models/mentor/application_spec.rb b/spec/models/mentor/application_spec.rb index ccaf3e046..da468f4c5 100644 --- a/spec/models/mentor/application_spec.rb +++ b/spec/models/mentor/application_spec.rb @@ -66,7 +66,7 @@ let(:projects) { Project.where(id: project1.id) } it "returns an empty array" do - last_season = Season.create name: Date.today.year-1 + last_season = Season.create name: Date.today.year - 1 create(:application, :for_project, project1: project1, season: last_season) expect(subject).to eq [] end diff --git a/spec/models/season_spec.rb b/spec/models/season_spec.rb index 7aec4b58c..5b809021d 100644 --- a/spec/models/season_spec.rb +++ b/spec/models/season_spec.rb @@ -36,7 +36,7 @@ it 'sets the project_proposals_close_at to the end of the day' do date = DateTime.parse('2015-02-22 14:00 GMT+1') - subject.project_proposals_close_at= date + subject.project_proposals_close_at = date expect { subject.valid? }.to \ change { subject.project_proposals_close_at }.to \ DateTime.parse('2015-02-22 23:59:59.999999999 GMT') @@ -142,7 +142,7 @@ let(:year) { Date.today.year } context 'with existing successor season' do - let!(:next_season) { Season.create name: year+1 } + let!(:next_season) { Season.create name: year + 1 } it 'returns the existing follow-up season' do expect { subject }.not_to change { Season.count } @@ -152,14 +152,14 @@ it 'creates the successor if it doesn\'t exist' do expect { subject }.to change { Season.count }.by(1) - expect(subject.name).to eql (year+1).to_s + expect(subject.name).to eql (year + 1).to_s end it 'sets the dates into the following year' do - expect(subject.starts_at.year).to eql year+1 - expect(subject.ends_at.year).to eql year+1 - expect(subject.applications_open_at.year).to eql year+1 - expect(subject.applications_close_at.year).to eql year+1 + expect(subject.starts_at.year).to eql year + 1 + expect(subject.ends_at.year).to eql year + 1 + expect(subject.applications_open_at.year).to eql year + 1 + expect(subject.applications_close_at.year).to eql year + 1 end end @@ -212,4 +212,4 @@ expect(Season.all_years).to match_array ['2015', '2016'] end end -end \ No newline at end of file +end diff --git a/spec/models/team_performance_spec.rb b/spec/models/team_performance_spec.rb index dcc8f6a24..044c12297 100644 --- a/spec/models/team_performance_spec.rb +++ b/spec/models/team_performance_spec.rb @@ -93,7 +93,7 @@ def create_all_teams context "during the season" do before :each do - current_season = build :season, acceptance_notification_at: 14.days.ago, starts_at: 10.days.ago, ends_at: 2.months.from_now + current_season = build :season, acceptance_notification_at: 14.days.ago, starts_at: 10.days.ago, ends_at: 2.months.from_now allow(Season).to receive(:current).and_return(current_season) end @@ -157,7 +157,7 @@ def create_all_teams context "after the season" do before :each do - past_season = build :season, starts_at: 2.months.ago, ends_at: 10.days.ago + past_season = build :season, starts_at: 2.months.ago, ends_at: 10.days.ago allow(Season).to receive(:current).and_return(past_season) end diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index 28e164a35..526cb1126 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -148,8 +148,8 @@ end describe '#coaches_confirmed?' do - let(:role) { FactoryGirl.create "#{role_name}_role" } - let(:role_name) { 'coach' } + let(:role) { FactoryGirl.create "#{role_name}_role" } + let(:role_name) { 'coach' } let(:member) { role.user } let(:user) { create(:user) } let(:team) { FactoryGirl.create(:team) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 01f5fc68a..d6de5aa5f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -225,12 +225,12 @@ describe '#name_or_handle' do it 'returns name if existed' do @user = described_class.new(name: 'trung') - expect(@user.name_or_handle).to be =='trung' + expect(@user.name_or_handle).to be == 'trung' end it 'returns github_handle if name is not available' do @user = described_class.new(github_handle: 'rails-girl') - expect(@user.name_or_handle).to be =='rails-girl' + expect(@user.name_or_handle).to be == 'rails-girl' end end @@ -348,18 +348,18 @@ @student_team = @student.teams.first end - it 'the method student_team return the student current team' do - expect(@student.student_team).to eql @student_team - end + it 'the method student_team return the student current team' do + expect(@student.student_team).to eql @student_team + end - it 'does not return student_team if when a user is not a student' do - expect(@user_not_student.student_team).to eql nil - end + it 'does not return student_team if when a user is not a student' do + expect(@user_not_student.student_team).to eql nil + end - it 'does not return student_team if student does not have a team' do - @student.teams.first.destroy - expect(@student.student_team).to eql nil - end + it 'does not return student_team if student does not have a team' do + @student.teams.first.destroy + expect(@student.student_team).to eql nil + end end describe 'Search for user names and team names' do diff --git a/spec/routing/comments_routing_spec.rb b/spec/routing/comments_routing_spec.rb index 9289b667b..2ea0ff248 100644 --- a/spec/routing/comments_routing_spec.rb +++ b/spec/routing/comments_routing_spec.rb @@ -14,4 +14,4 @@ expect(post('/comments')).to route_to('comments#create') end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d286b6d58..4466a6b3d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -42,7 +42,7 @@ config.include ActiveJob::TestHelper config.include RSpecHtmlMatchers - config.extend ControllerMacros, type: :controller + config.extend ControllerMacros, type: :controller config.infer_spec_type_from_file_location! diff --git a/spec/support/capture_system_io.rb b/spec/support/capture_system_io.rb index 410045361..ba016f91d 100644 --- a/spec/support/capture_system_io.rb +++ b/spec/support/capture_system_io.rb @@ -5,6 +5,6 @@ end after :all do - $> = @old_stdout + $> = @old_stdout end end diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb index 9794b58a0..eec437fb3 100644 --- a/spec/support/factory_girl.rb +++ b/spec/support/factory_girl.rb @@ -1,3 +1,3 @@ RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods -end \ No newline at end of file +end diff --git a/spec/support/shared_examples/redirect_for_non_admins.rb b/spec/support/shared_examples/redirect_for_non_admins.rb index ba3479c65..de4a1b5ba 100644 --- a/spec/support/shared_examples/redirect_for_non_admins.rb +++ b/spec/support/shared_examples/redirect_for_non_admins.rb @@ -14,7 +14,7 @@ context 'logged in as non-admin' do before do - user = mock_model('User', :admin? => false) + user = mock_model('User', admin?: false) allow(controller).to receive(:current_user).and_return(user) end diff --git a/spec/support/shared_examples/redirect_for_non_students.rb b/spec/support/shared_examples/redirect_for_non_students.rb index 0223f2766..3a574ac91 100644 --- a/spec/support/shared_examples/redirect_for_non_students.rb +++ b/spec/support/shared_examples/redirect_for_non_students.rb @@ -43,7 +43,7 @@ end context 'who is part of an accepted team from last season' do - let(:last_season) { Season.create name: Date.today.year-1 } + let(:last_season) { Season.create name: Date.today.year - 1 } let(:accepted_team) { create :team, season: last_season, kind: 'sponsored' } let(:user) { create(:student_role, team: accepted_team).user } it_behaves_like 'disallows access to students namespace'