Skip to content

Commit

Permalink
Add books, scaffolding generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Macey committed Jan 17, 2017
1 parent c9053cf commit e978447
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gem 'active_scaffold', github: 'activescaffold/active_scaffold'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
GIT
remote: https://github.com/activescaffold/active_scaffold.git
revision: ae05822c8e067cf381a4f7df2758643630d07c2d
specs:
active_scaffold (3.4.99)
ice_nine (~> 0.11)
rails (>= 4.0.5)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -66,6 +74,7 @@ GEM
globalid (0.3.7)
activesupport (>= 4.1.0)
i18n (0.7.0)
ice_nine (0.11.2)
jbuilder (2.6.1)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
Expand Down Expand Up @@ -184,6 +193,7 @@ PLATFORMS
ruby

DEPENDENCIES
active_scaffold!
byebug
capybara
coffee-rails (~> 4.2)
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// about supported directives.
//
//= require jquery
//= require active_scaffold
//= require jquery_ujs
//= require turbolinks
//= require_tree .
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
*
*= require_tree .
*= require_self
*= require active_scaffold
*/
4 changes: 4 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class BooksController < ApplicationController
active_scaffold :"book" do |conf|
end
end
2 changes: 2 additions & 0 deletions app/helpers/books_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BooksHelper
end
2 changes: 2 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Book < ApplicationRecord
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Rails.application.routes.draw do
root to: 'books#index'

concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
resources :books, concerns: :active_scaffold
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
12 changes: 12 additions & 0 deletions db/migrate/20170117212243_create_books.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateBooks < ActiveRecord::Migration[5.0]
def change
create_table :books do |t|
t.string :title
t.string :author
t.string :year_published
t.text :description

t.timestamps
end
end
end
27 changes: 27 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170117212243) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "books", force: :cascade do |t|
t.string "title"
t.string "author"
t.string "year_published"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
18 changes: 18 additions & 0 deletions spec/features/books_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails_helper'

describe "creating a book", type: :feature do
it "creates a new book" do
visit "/books/new"
within "#as_books-create--form" do
fill_in "Title", with: "Pro Git"
fill_in "Author", with: "Scott Chacon"
fill_in "Description", with: <<-EOF.strip_heredoc
Git is the version control system developed by Linus Torvalds for Linux
kernel development. It took the open source world by storm since its
inception in 2005, and is used by small development shops and giants like
Google, Red Hat, and IBM, and of course many open source projects.
EOF
fill_in "Year published", with: "2009"
end
end
end

0 comments on commit e978447

Please sign in to comment.