├── LICENSE ├── README.md └── rails_and_gems_anki_deck.txt /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Paul-Etienne Coisne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # anki_rails 2 | Collection of [Anki](http://ankisrs.net/) flashcards pertaining to Ruby, Rails and major gems 3 | 4 | Currently the deck contains: 5 | ```ruby 6 | Rails = %w(validations) 7 | Gems = %w(rspec-rails) 8 | ``` 9 | 10 | I am in the process of adding more of [Active Record](ACtiveadmin.info) and Rails elements such as basic helpers, [Active Support](http://guides.rubyonrails.org/active_support_core_extensions.html) etc, and this repo will be updated along the way. Stay tuned! 11 | 12 | ===== 13 | 14 | This is a raw export of the actual package, which may be found on [AnkiWeb](https://ankiweb.net/decks/): 15 | 16 | https://ankiweb.net/shared/info/1642358939 17 | 18 | The [main file](https://github.com/coisnepe/anki_rails/blob/master/rails_and_gems_anki_deck.txt) is formatted with syntax highlighting specifically for Anki. I'll try to convert it to a more versatile csv for use in third-party apps. 19 | 20 | You're welcome and encouraged to collaborate on this project; simply fork and make pull requests from your `master` branch! 21 | 22 | 23 | ### Todo 24 | ```ruby 25 | Gems << %w(factory_bot_rails capybara shoulda paperclip cancancan sass pundit sequel) 26 | ``` 27 | -------------------------------------------------------------------------------- /rails_and_gems_anki_deck.txt: -------------------------------------------------------------------------------- 1 | [Rails] Validate that a user checked a box in a form "
validates :terms_of_services, acceptance: true
" http://guides.rubyonrails.org/active_record_validations.html#acceptance activerecord rails validations 2 | [Rails] Validate that if a model has associated models, validate them too. "
has_many :books  
validates_associated :books
" http://guides.rubyonrails.org/active_record_validations.html#validates-associated activerecord rails validations 3 | [Rails] Validate that two fields have the same content "
validates :email, confirmation: true
validates :email_confirmation, presence: true
<%= text_field :person, :email %>
<%= text_field :person, :email_confirmation %>
" http://guides.rubyonrails.org/active_record_validations.html#confirmation activerecord marked rails validations 4 | [Rails] Validate that attributes' values are not included "
class Account < ActiveRecord::Base
validates :subdomain, exclusion: { in: %w(www us ca jp),
message: ""%{value} is reserved."" }
end
" http://guides.rubyonrails.org/active_record_validations.html#exclusion activerecord rails validations 5 | [Rails] Validate attributes with Regex "
class Product < ActiveRecord::Base
validates :legacy_code, format: { with: /\A[a-zA-Z]+\z/,
message: ""only allows letters"" }
end
" http://guides.rubyonrails.org/active_record_validations.html#format activerecord rails validations 6 | [Rails] Validate inclusion of attributes in a given set "
class Coffee < ActiveRecord::Base
validates :size, inclusion: { in: %w(small medium large),
message: ""%{value} is not a valid size"" }
end
" http://guides.rubyonrails.org/active_record_validations.html#inclusion activerecord rails validations 7 | [Rails] Validate length "
validates :name, length: { minimum: 2 }
validates :bio, length: { maximum: 500 }
validates :password, length: { in: 6..20 }
validates :registration_number, length: { is: 6 }
" http://guides.rubyonrails.org/active_record_validations.html#length activerecord rails validations 8 | [Rails] Validate numerical values "
validates :points, numericality: true
validates :games_played, numericality: { only_integer: true }
:greater_than
:greater_than_or_equal_to
:equal_to
:less_than
:less_than_or_equal_to
:odd
:even
" http://guides.rubyonrails.org/active_record_validations.html#numericality activerecord marked rails validations 9 | [Rails] Validate presence of attribute "
validates :name, :login, :email, presence: true
" http://guides.rubyonrails.org/active_record_validations.html#presence activerecord rails validations 10 | [Rails] Validate absence "
validates :name, :login, :email, absence: true

This helper validates that the specified attributes are absent. It uses the present? method to check if the value is not either nil or a blank string, that is, a string that is either empty or consists of whitespace.
" activerecord rails validations 11 | [Rails] Validate that an attribute is unique "
validates :email, uniqueness: true

validates :name, uniqueness: { scope: :year,
message: ""should happen once per year"" }

validates :name, uniqueness: { case_sensitive: false }
" http://guides.rubyonrails.org/active_record_validations.html#uniqueness activerecord rails validations 12 | [Rails] Use custom validators "
class GoodnessValidator < ActiveModel::Validator
def validate(record)
    if record.first_name == ""Evil""
record.errors[:base] << ""This person is evil""
end
end
end

class Person < ActiveRecord::Base
validates_with GoodnessValidator
end
" http://guides.rubyonrails.org/active_record_validations.html#validates-with activerecord rails validations 13 | [Rails] Validate against a block "This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to validates_each will be tested against it. In the following example, we don't want names and surnames to begin with lower case.


class Person < ActiveRecord::Base
validates_each :name, :surname do |record, attr, value|
record.errors.add(attr, 'must start with upper case') if value =~ /\A[[:lower:]]/
end
end
" http://guides.rubyonrails.org/active_record_validations.html#validates-each activerecord rails validations 14 | [Rails] Validate to allow nil "
class Coffee < ActiveRecord::Base
validates :size, inclusion: { in: %w(small medium large),
message: ""%{value} is not a valid size"" }, allow_nil: true
end
" http://guides.rubyonrails.org/active_record_validations.html#allow-nil activerecord rails validations 15 | [Rails] Validation to allow an attribute to be blank "
class Topic < ActiveRecord::Base
validates :title, length: { is: 5 }, allow_blank: true
end
" http://guides.rubyonrails.org/active_record_validations.html#allow-blank activerecord rails validations 16 | [Rails] Validation to specify on which action it should take place "
validates :age, numericality: true, on: :update
validates :email, uniqueness: true, on: :create
" http://guides.rubyonrails.org/active_record_validations.html#on activerecord rails validations 17 | [Rails] Change tables "
change_table :products do |t|
t.remove :description, :name
t.string :part_number
t.index :part_number
t.rename :upccode, :upc_code
end
" http://guides.rubyonrails.org/active_record_migrations.html#changing-tables activerecord migrations rails 18 | [Rspec] Install Rspec in rails "
gem 'rspec-rails',


$ rails generate rspec:install" https://github.com/rspec/rspec-rails gem rails rspec 19 | [Rspec] Setup for test "
require ""rails_helper""

RSpec.describe User, type: :model do
it ""orders by last name"" do
lindeman = User.create!(first_name: ""Andy"", last_name: ""Lindeman"")
chelimsky = User.create!(first_name: ""David"", last_name: ""Chelimsky"")
expect(User.ordered_by_last_name).to eq([chelimsky, lindeman])
end
end
" https://github.com/rspec/rspec-rails gem rails rspec 20 | [Rspec] Expect result to be true "
expect(foo.bar?).to be_truthy
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 21 | [Rspec] Expect result to be false "
expect(foo.bar?).to be_falsey
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 22 | [Rspec] Expect result to be nil "
expect(foo.bar?).to be_nil
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 23 | [Rspec] Expect result to equal something "
expect(user.id).to eq(""foo"")
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 24 | [Rspec] Expect result to be of a certain class/type "
expect(user).to be_a(FooApp::User)
expect(arr).to be_an(Array)
"
http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/
gem rails rspec 25 | [Rspec] Check a result against a Regex "
expect(user.id).to match(/foo/)
"
http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/
gem rails rspec 26 | [Rspec] Check inclusion of something in result "
expect([1, 2, 3]).to include(2)
expect(request.headers).to include(""X-Foo"" => ""bar"", ""X-Baz"" => ""qux"")
expect(request.headers).to have_key(""X-Foo"")
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 27 | [Rspec] Check every object/item of a result to adhere to a statement "
expect([1, 2, 3]).to all(be_a(Fixnum))
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 28 | [Rspec] How do you check errors? "
expect { Foo.find(-1) }.to raise_error(ActiveResource::ResourceNotFound)
expect { Foo.find(1) }.not_to raise_error
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 29 | [Rspec] Check that an action renders the right template "
get :index
expect(response).to render_template(""index"")
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 30 | [Rspec] Check a controller's method with given params "
expect(get(""/foo?bar=baz"")).to route_to(controller: ""foo"", action: ""method"", bar: ""baz"")
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 31 | [Rspec] Check that an object responds to a given method "
expect(foo).to respond_to(:bar)
" http://www.cheatography.com/mpicker0/cheat-sheets/rspec-3-expectations/ gem rails rspec 32 | [Rspec] How many kinds of specs are there? Name them. "8:
type: :model
type: :controller
type: :request
type: :feature
type: :view
type: :helper
type: :mailer
type: :routing
" https://www.relishapp.com/rspec/rspec-rails/docs/directory-structure gem rails rspec 33 | [Rspec] Check that a url is not rendered "
it ""does not expose a list of profiles"" do
expect(get: ""/profiles"").not_to be_routable
end
" gem rails rspec 34 | [Rspec] What does 'transactional fixtures' mean? "
RSpec.configure do |config|
config.use_transactional_fixtures = true
end


If true, fixtures/factories will be recreated for each example when using before(:each). before(:all) disregards this setting." https://relishapp.com/rspec/rspec-rails/v/3-4/docs/transactions rails rspec 35 | [Rspec][Controller] For a given action, how do you check that the correct template is rendered? "
expect(response).to render_template(:new)
" https://www.relishapp.com/rspec/rspec-rails/docs/matchers/render-template-matcher rails rspec 36 | [Rspec][Controller] How do you check routes and redirections? "
expect(response).to redirect_to(location)
" https://www.relishapp.com/rspec/rspec-rails/docs/matchers/redirect-to-matcher rails rspec 37 | [Rspec][Controller] How do you check the http status of the request? "
expect(response).to have_http_status(:created)
" https://www.relishapp.com/rspec/rspec-rails/docs/matchers/have-http-status-matcher rails rspec 38 | [Rspec][Controller] New "
expect(assigns(:widget)).to be_a_new(Widget)
" https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs rails rspec 39 | --------------------------------------------------------------------------------