This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| root to: 'dashboard#index' | |
| get 'signin' => 'sessions#new' | |
| root 'dashboard#index' | |
| get 'signin', to: 'sessions#new' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ApplicationHelper | |
| def admins_only | |
| yield if current_user.try(:admin?) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| assert_selector 'article', count: Article.count | |
| assert_selector 'article', exact: Article.count | |
| assert find_button('Save article', disabled: true).disabled? | |
| assert has_link?('New article', href: new_article_path) | |
| # assert that a link with text 'New article' and href new_article_path exists | |
| # not necessarily good to track bugs | |
| assert_equal new_article_path, find('a', text: 'New article')[:href] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'test_helper' | |
| class ArticleTest < ActiveSupport::TestCase | |
| delegate :validators_on, to: Article | |
| test "validates presence of title" do | |
| refute_emtpy validators_on(:title).grep PresenceValidator | |
| end | |
| private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DEFAULTS (notice and alert) | |
| flash.notice = 'notice' | |
| flash[:notice] = 'notice' | |
| redirect_to root_url, notice: 'notice' | |
| notice # in view | |
| # CUSTOM TYPES | |
| add_flash_types :warning |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'capybara/rails' | |
| require 'capybara/poltergeist' | |
| class ActionDispatch::IntegrationTest | |
| include Capybara::DSL | |
| Capybara.javascript_driver = :poltergeist | |
| setup do | |
| Capybara.current_driver = Capybara.javascript_driver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ rails g model user email | |
| =begin | |
| create_table :users do |t| | |
| t.string :email | |
| t.timestamp | |
| end | |
| =end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person; def hello; 'hello'; end; end; | |
| Person.new.tap do |p| | |
| puts p.hello | |
| end.tap do |p| | |
| puts p.hello | |
| end | |
| Person.new.tap { |p| | |
| puts p.hello |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'markdown' | |
| class Article < ActiveRecord::Base | |
| before_save do | |
| self.html = Markdown.new(content).to_html | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).on('blur', '#input', function(e) { | |
| var $this = $(this); | |
| setTimeout(function() { | |
| $this.focus(); | |
| }); | |
| }); |