AstroCamp 6th
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 1106_ruby_day4 [![hackmd-github-sync-badge](https://hackmd.io/rhCCiyiLRYeZte3LbM-bVQ/badge)](https://hackmd.io/rhCCiyiLRYeZte3LbM-bVQ) --- #### 上課日期:1106 ###### tags: `ruby` ###### tags: `5xruby` --- # 相關連結: - [課程影片](https://campus.5xruby.tw/courses/1136422/lectures/25361517) --- # 0. 綱要/目錄 - [ ] 測試TDD-基本介紹 - [ ] 測試TDD-各種小知識 - [ ] Rails專案 --- # 1. 測試驅動開發 TDD(Test-Driven Development) >- 不會就找不到ruby工作!!! >- 在寫程式之前,先寫一個測試(程式),如果程式可以通過測試,程式就可執行。 - 這是一種開發方式,一種安全網的概念 - 先寫一段code去驗證另外一段code是否可行 - 先寫測試,再寫程式 #### 實行時的想法 - 測試不存在的功能,假設它可以正常運作 - 測試失敗時,可以修正這個問題 >>> 知道哪裡有問題,修改後,才會變成「沒有問題」。 #### 安裝 - 測試套件minitest與 RSpec(框架): - minitest為ruby內建 - 但RSpec比較好寫、通用 - 安裝 `$ gem install rspec` #### 角色 - 寫程式時工程師 - 寫測試時是PM、使用者 --- ## 1.1. 各種小知識 ### 1.1.1. 版號命名規則 | <center>4.0.0</center> |3.10.0 | 3.8.2 | 3.8.0 | | -------- | -------- | -------- |-------- | | major / minor / patch | | | - patch 修改小地方 - minor 修改一些功能,有可能不相容 - major 大改版,通常不會向下相容 - rails 目前(2020.11.06)版本是6.0.3.4 - 接下來的版本是6.1-rc(release candidate),表示準備要發布的版本,基本不會有什麼大修改 ### 1.1.2. Ruby特有種 - Rake = Ruby Make - RSpec = Ruby Spec - Spec:specification 規範/規格書 ##### 延伸閱讀 - [軟體版本編號(wiki)](https://zh.wikipedia.org/wiki/%E8%BB%9F%E4%BB%B6%E7%89%88%E6%9C%AC%E8%99%9F) --- #### AAA 3A原則 - arrange 先排列好 - act 操作它 - assert 判斷它完成 #### 省略原則 - 通常小括號、大括號或 return可省略不寫 - 想法:盡量省略,讓ruby看起來像英文 - 注意:但如果會影響判斷的話,就不要省略 #### singleton method單體/單例方法 - 目的:保證一個類別只會產生一個物件,而且要提供存取該物件的統一方法 #### 變數前的@ - 有些人不清楚規則,就全部都加 - 全部都加不會有問題,但就是很多餘 - "@"有記憶功能 - [Ruby Memoization](https://blog.niclin.tw/2019/08/04/ruby-memoization/) #### ruby沒有屬性 - `attr_reader :xxxx` - attr = Attributes 屬性 --- #### review question - TDD是寫程式來測試程式,那誰來測試TDD? - 遵循3A原則,用肉眼來測試TDD - 為什麼要寫測試? #### 測試後的符號 "`.`":完成(幾個點就代表有幾個examples) ![](https://i.imgur.com/PeZR4Se.png) "`*`":pending 有東西還沒做(it 方法如果後面沒有加上 Block,預設會是 pending 狀態) ![](https://i.imgur.com/qECjmfY.png) --- --- # Rails專案 ## 1. [可挑戰題目(1102)](https://discord.com/channels/748042598983401482/748046752870826045/772781415896449034) - Dcard - 巴哈姆特 - Mobile01 (phpbb/discuz/wordpress/drumla) - iThome 鐵人賽 - Pinterest / IG - 財報狗 / 虛擬貨幣網站 - 電商 / 購物 - Pocket / Chrome Extension ## 高級題目 - Hey.com - VSCode Electron(HTML/CSS/JS) --- ## 2. 以Dcard為例 - 會員系統 - email / password - nickname - account - avatar 大頭照 - school - 看板 - 分類 - 名稱 - 文章s - 標題title - 作者author - 內文content - 回應s ### 重新分類 - User - has_many Boards - has_many Posts - has_many Comments - Category - has_many Boards - Board - belongs_to Category - has_many Posts - belong_to User 版主/管理員 - Post - has_many Comments - belongs_to User - belongs_to Board - Comment - belongs_to Post - belongs_to User ### 重新分類2 > 畫圖 ## 建立專案 1. 找一個適合的地方建立專案資料夾 `$ rails new NAME` 2. 進入到該資料夾 `cd NAME` `rails s` :::info `rails server` > `rails s` rails server 命令會啟動一個小型的網路伺服器,叫做 WEBrick,是 Ruby 內建的伺服器。想要在瀏覽器存取 Rails 應用程式,使用 rails server 來啟動伺服器。 ::: 3. 確認專案已建立,在瀏覽器鍵入,`localhost:3000` 4. 建立基本資料 `$ rails g model User email password nickname account avatar school` - 如果打錯的話:`$ rails b model User email password nickname account avatar school`,將g改成b,再打一次 5. 進入資料夾 xxx > db > migrate - Migration這個資料夾的目的是什麼? - 描述說接下來這個表格掌什麼樣子 - 跟model沒有(直接)關係 - Migration是跟table有關係,但不是一對一 - 東西做錯的話,新增一個migration再去修正它 - 用途:紀錄所有資料的欄位和意義 6. 修改,可先進入沙盒模式模擬: - `$ rails console --snadbox` - 離開:ctl+d or exit ----- --- # 附件 - [上課投影片](https://discord.com/channels/748042598983401482/748046752870826045/774152748664094750) - [Ping-Pong, Paired Programing](https://thoughtbot.com/upcase/videos/ping-pong-paired-programing)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully