View post-merge
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
View post-merge
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# forked by Gianluca Guarini
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep -E --quiet "$1" && eval "$2"
}
View spec_helper.rb
require 'simplecov'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
SimpleCov.start
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
View codeclimate gem file
group :test do
gem 'simplecov'
gem 'codeclimate-test-reporter', '~> 1.0.0'
end
View config.yml
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
View .travis.yml
language: ruby
rvm:
- 2.3.1
env:
- DB=sqlite
before_script:
- mysql -e 'create database test;'
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rspec && CODECLIMATE_REPO_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX bundle exec codeclimate-test-reporter
View association_models.rb
1.belongs_to association:
---------------------
- Student and College:
- a student belongs_to college
- college_id is present in the college
- Example:
**************
class Student < ApplicationRecord
belongs_to :college
View Collect_Select_Map_Inject_Reject_Detect.rb
map and collect are same http://stackoverflow.com/questions/5254732/difference-between-map-and-collect-in-ruby
http://matthewcarriere.com/2008/06/23/using-select-reject-collect-inject-and-detect/
1. Use select or reject if you need to select or reject items based on a condition.
2. Use collect if you need to build an array of the results from logic in the block.
3. Use inject if you need to accumulate, total, or concatenate array values together.
4. Use detect if you need to find an item in an array.
View ruby_mistakes.rb
Dont misuse predicate methods:
-------
predicate methods used to return either true or false. they ends with "?"
It’s been a while since we’ve rolled out our previous article about the most common Rails mistakes that beginner developers usually make. In this regard, we aren’t going to bother you with too much of introduction and get straight to the point. This article will be dedicated to the standard approaches to Ruby development which are also called “the Ruby way”. As usual, the most critical mistakes are highlighted with RED. So, let’s find out what exactly newbies do wrong/forget to do or don’t do at all.
They misuse predicates
A predicate is a method that answers a specific question and always returns either “yes” or “no”. It’s not supposed to affect any other piece of code or perform any additional actions. According to the Ruby on Rails style guides, predicates are followed by a question mark at the end of the method name.
############
## WRONG ##
View controller_mistakes.rb
Use variables as instance variables when used.
----------------------
beginners declare all the variables in controllers as instances even if it may not be required.
The problem with instance variables is that if you make a mistake, you won’t get the error message.
A good practice here is to use one or two instance variables per action
###############
## WRONG ##
###############