Skip to content
Permalink
Browse files

Start writing documentation.

  • Loading branch information...
dmitryrck committed Mar 25, 2019
1 parent 4ae59d4 commit 2847507734afd434d6f5c130e5eb852183f7b2bf
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,19 @@
class DocsController < ApplicationController
layout "docs"

def index
@docs = Doc.all
@description = ""
end

def show
@doc = Doc.new(params[:id])

@title = @doc.title
@description = @doc.description

if @doc.invalid?
render "show", status: 404
end
end
end
@@ -0,0 +1,61 @@
class Doc
attr_reader :doc_id

def initialize(doc_id)
@doc_id = doc_id
end

def self.all
list.keys.map { |doc_id| Doc.new(doc_id) }
end

def self.list
if Rails.env.production?
@list ||= Psych.load(File.read(Rails.root.join(BASE_DIR, "index.yml")))
else
Psych.load(File.read(Rails.root.join(BASE_DIR, "index.yml")))
end
end

def title
list.fetch(@doc_id) { { "title" => "Not found" } }["title"]
end

def description
list.fetch(@doc_id) { { "description" => "" } }["description"]
end

def path
return not_found if invalid?

@path ||= Rails.root.join(BASE_DIR, @doc_id + ".html.erb")
end

def url
"/#{BASE_DIR}/#{@doc_id}"
end

def invalid?
!valid?
end

private

BASE_DIR = "docs".freeze

def not_found
Rails.root.join(BASE_DIR, "not_found.html.erb")
end

def whitelist
list.keys
end

def valid?
whitelist.include?(@doc_id)
end

def list
self.class.list
end
end
@@ -0,0 +1,5 @@
<ul>
<% Doc.all.each do |doc| %>
<li><%= link_to doc.title, doc.url %></li>
<% end %>
</ul>
@@ -0,0 +1,5 @@
<ul>
<% @docs.each do |doc| %>
<li><%= link_to doc.title, doc.url %></li>
<% end %>
</ul>
@@ -0,0 +1,5 @@
<%= render "header" %>

<h2><%= @doc.title %></h2>

<%= render file: @doc.path %>
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Organize2 - <%= @title %></title>
<meta name="description" content="<%= @description %>">
</head>
<body>
<%= yield %>
</body>
</html>
@@ -3,4 +3,5 @@
ActiveAdmin.routes(self)

root to: "admin/outgos#index"
resources :docs, only: %i[index show]
end
@@ -0,0 +1,25 @@
<p>
After loggining click in <em><%= Account.model_name.human(count: 2) %></em>:
</p>

<%= image_tag "screenshots/create_account_01" %>

<p>
Click in <em>New Account</em>, and then you will see this form:
</p>

<%= image_tag "screenshots/create_account_02" %>

<p>
Fill, at least, the <em><%= Account.human_attribute_name(:name) %></em> field and click in <em>Create Account</em>.
</p>

<p>
After that your screen will look like this:
</p>

<%= image_tag "screenshots/create_account_03" %>

<p>
And your account is created.
</p>
@@ -0,0 +1,3 @@
create_account:
title: "Create an Account"
description: "How to create an Account"
@@ -0,0 +1 @@
Not found.
@@ -33,15 +33,23 @@

it "should be able to create" do
click_on "Accounts"

page.driver.browser.manage.window.resize_to(1024, 768)
page.driver.save_screenshot Rails.root.join("app/assets/images/screenshots/create_account_01.png"), full: true

click_on "New"

fill_in "Name", with: "Account#1"
fill_in "Start balance", with: 123.45
fill_in "Currency", with: "USD"
fill_in "Precision", with: 4

page.driver.save_screenshot Rails.root.join("app/assets/images/screenshots/create_account_02.png"), full: true

click_on "Create"

page.driver.save_screenshot Rails.root.join("app/assets/images/screenshots/create_account_03.png"), full: true

expect(page).to have_content("Account#1")
expect(page).to have_content("START BALANCE USD123.45")
expect(page).to have_content("BALANCE USD123.45")
@@ -0,0 +1,58 @@
require "rails_helper"

describe Doc do
before do
allow(Doc).to receive(:list).and_return({
"something" => {
"title" => "Something title" ,
"description" => "Something description",
}
})
end

context "#all" do
it "should be an array of Doc objects" do
expect(Doc.all[0]).to be_an_instance_of Doc
end
end

context "when instance is valid" do
subject { Doc.new("something") }

it "should have an title" do
expect(subject.title).to eq "Something title"
end

it "should have an description" do
expect(subject.description).to eq "Something description"
end

it "should have a url" do
expect(subject.url).to eq "/docs/something"
end

it "should have a path" do
expect(subject.path.to_s).to match %r[/docs/something.html.erb]
end
end

context "when instance is invalid" do
subject { Doc.new("something2") }

it "title should be not found by default" do
expect(subject.title).to eq "Not found"
end

it "should not have an description" do
expect(subject.description).to be_blank
end

it "should have a url" do
expect(subject.url).to eq "/docs/something2"
end

it "should have a path" do
expect(subject.path.to_s).to match %r[/docs/not_found.html.erb]
end
end
end

0 comments on commit 2847507

Please sign in to comment.
You can’t perform that action at this time.