From 414d1c3ac5dfefcb75b973ff63e4595037938fe4 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Mon, 25 Apr 2016 15:55:29 +0800 Subject: [PATCH] Update --- brunch.md | 71 ++++++++++++++++++++++++++++----------------- metalsmith.md | 1 - rails-migrations.md | 5 ++++ rails-routes.md | 29 ++++++++++++++---- rspec-rails.md | 16 +++------- 5 files changed, 77 insertions(+), 45 deletions(-) diff --git a/brunch.md b/brunch.md index 6b8ec3290..a5bd7574d 100644 --- a/brunch.md +++ b/brunch.md @@ -14,33 +14,52 @@ category: JavaScript libraries ## Config - files: - javascripts: # or 'stylesheets' or 'templates' - order: - before: [ 'normalize.css' ] - after: [ 'helpers.css' ] +```js +module.exports = { + files: { + javascripts: { # or 'stylesheets' or 'templates' + order: { + before: [ 'normalize.css' ], + after: [ 'helpers.css' ], - joinTo: 'app.js' - joinTo: - 'js/app.js': /^app/ - 'js/vendor.js': /^vendor/ - pluginHelpers: 'js/vendor.js' + joinTo: 'app.js', + joinTo: { + 'js/app.js': /^app/, + 'js/vendor.js': /^vendor/ + }, + pluginHelpers: 'js/vendor.js' + } + } - paths: - public: 'public' # where to compile - watched: ['app','test','vendor'] # what to monitor + paths: { + public: 'public', # where to compile + watched: ['app','test','vendor'], # what to monitor + } - modules: - wrapper: 'amd' - definition: 'amd' - nameCleaner: (path) -> path.replace /^app\//, '' + modules: { + wrapper: 'amd', + definition: 'amd', + nameCleaner: (path) => path.replace(/^app\//, '') + } - # brunch b --apply production - overrides: - production: - optimize: true - sourceMaps: false - plugins: autoReload: enabled: false + npm: { styles, globals } + + plugins: { + sass: { ... } + } + + // brunch w --apply testing + // BRUNCH_ENV=testing brunch build + overrides: { + production: { + optimize: true, + sourceMaps: false, + plugins: { autoReload: { enabled: false } } + } + } + + onCompile: (files, assets) => { ... } +``` ## Plugins @@ -53,11 +72,11 @@ category: JavaScript libraries ## Extensions -Compile to JS/CSS +Compile to CSS * stylus-brunch - * coffee-script-brunch * less-brunch + * sass-brunch Compile to HTML @@ -75,4 +94,4 @@ Etc ## References - * https://github.com/brunch/brunch/blob/master/docs/config.md + * diff --git a/metalsmith.md b/metalsmith.md index 2ba8e721b..8e465844a 100644 --- a/metalsmith.md +++ b/metalsmith.md @@ -19,4 +19,3 @@ Use `{{ contents }}` to bring it out Engines: * swig (like liquid) - diff --git a/rails-migrations.md b/rails-migrations.md index c3e16dcb1..61b8035e5 100644 --- a/rails-migrations.md +++ b/rails-migrations.md @@ -110,6 +110,11 @@ category: Rails add_index :accounts, [:branch_id, :party_id, :surname], :order => {:branch_id => :desc, :part_id => :asc} +### In console +Use `ActiveRecord::Migration`. + + ActiveRecord::Migration.add_index :posts, :slug + ### References * http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/add_index diff --git a/rails-routes.md b/rails-routes.md index 5677a83d3..84fc39f08 100644 --- a/rails-routes.md +++ b/rails-routes.md @@ -3,9 +3,10 @@ title: Routes category: Rails --- -### Multiple resources +## Multiple resources (`resources`) resources :books + # PhotosController: # index => GET /photos # new => GET /photos/new @@ -19,16 +20,32 @@ category: Rails # new_book_path # book_path(id) # edit_book_path(id) - # + +### Custom actions resources :photos do member { get 'preview' } # /photo/1/preview - get 'preview', on: :member # (..same as the first) collection { get 'search' } # /photos/search + + get 'preview', on: :member # (..same as the first) end -### Single resource - +### Options + + resources :photos, + path_names: { new: 'brand_new' } # /photos/1/brand_new + path: 'postings' # /postings + only: :index + only: [:index, :show] + except: :show + except: [:index, :show] + + shallow: true # also generate shallow routes + shalow_path: 'secret' + shallow_prefix: 'secret' + +## Single resource (`resource`) + resource :coder # CodersController: @@ -39,7 +56,7 @@ category: Rails # update => PUT /coder # delete => DELETE /coder -### Matching +## Matching (`match`) match 'photo/:id' => 'photos#show' # /photo/what-is-it match 'photo/:id', id: /[0-9]+/ # /photo/0192 diff --git a/rspec-rails.md b/rspec-rails.md index a2eac4e62..789036013 100644 --- a/rspec-rails.md +++ b/rspec-rails.md @@ -56,22 +56,14 @@ end # spec/requests/*.rb describe "home page" do it "displays the user's username after successful login" do - user = User.create!(:username => "jdoe", :password => "secret") - get "/login" - - assert_select "form.login" do - assert_select "input[name=?]", "username" - assert_select "input[name=?]", "password" - assert_select "input[type=?]", "submit" - end - post "/login", username: "jdoe", password: "secret" expect(response.status).to eql 200 - - # capybara - expect(page).to have_selector(".header .username", :text => "jdoe") + expect(response).to redirect_to(...) + expect(response).to render_template(:show) + expect(response.body).to include 'hello' + follow_redirect! end end ```