Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
refatored Post into Article
Browse files Browse the repository at this point in the history
  • Loading branch information
Jürgen Brüder committed Sep 30, 2015
1 parent aaf06c2 commit 42de4d0
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 208 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.sqlite3
*.sqlite3
Gemfile.lock
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org/'

gem "sinatra", "1.4.5"
gem "sinatra", "1.4.6"
gem "sqlite3", "1.3.10"
gem "activerecord", "4.2.0"
gem "sinatra-activerecord", "2.0.5"
Expand All @@ -15,7 +15,3 @@ group :development do
gem "shotgun", "0.9" # So we don't need to restart the server every time
gem "tux", "0.3.0" # A ruby console for testing
end

group :production do
gem "mysql", "2.9.1"
end
79 changes: 40 additions & 39 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (4.1.1)
activesupport (= 4.1.1)
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.1.1)
activemodel (= 4.1.1)
activesupport (= 4.1.1)
arel (~> 5.0.0)
activesupport (4.1.1)
i18n (~> 0.6, >= 0.6.9)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
arel (6.0.3)
bond (0.5.1)
builder (3.2.2)
capybara (2.4.1)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cucumber (1.3.17)
cucumber (1.3.18)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.1)
cucumber-sinatra (0.5.0)
templater (>= 1.0.0)
database_cleaner (1.3.0)
database_cleaner (1.4.0)
diff-lcs (1.2.5)
extlib (0.9.16)
gherkin (2.12.2)
multi_json (~> 1.3)
highline (1.6.21)
i18n (0.6.9)
json (1.8.1)
mime-types (2.3)
mini_portile (0.6.0)
minitest (5.3.4)
multi_json (1.10.1)
multi_test (0.1.1)
i18n (0.7.0)
json (1.8.3)
mime-types (2.6.2)
mini_portile (0.6.2)
minitest (5.8.1)
multi_json (1.11.2)
multi_test (0.1.2)
mysql (2.9.1)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rake (10.3.2)
ripl (0.7.1)
bond (~> 0.5.1)
ripl-multi_line (0.3.1)
Expand All @@ -75,22 +74,22 @@ GEM
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-activerecord (2.0.2)
sinatra-activerecord (2.0.5)
activerecord (>= 3.2)
sinatra (~> 1.0)
sqlite3 (1.3.9)
sqlite3 (1.3.10)
templater (1.0.0)
diff-lcs (>= 1.1.2)
extlib (>= 0.9.5)
highline (>= 1.4.0)
thread_safe (0.3.4)
thread_safe (0.3.5)
tilt (1.4.1)
tux (0.3.0)
ripl (>= 0.3.5)
ripl-multi_line (>= 0.2.4)
ripl-rack (>= 0.2.0)
sinatra (>= 1.2.1)
tzinfo (1.2.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand All @@ -99,16 +98,18 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord
capybara
cucumber
cucumber-sinatra
database_cleaner
mysql
rake
activerecord (= 4.2.0)
capybara (= 2.4.4)
cucumber (= 1.3.18)
cucumber-sinatra (= 0.5.0)
database_cleaner (= 1.4.0)
mysql (= 2.9.1)
rspec (= 2.99.0)
shotgun
sinatra
sinatra-activerecord
sqlite3
tux
shotgun (= 0.9)
sinatra (= 1.4.5)
sinatra-activerecord (= 2.0.5)
sqlite3 (= 1.3.10)
tux (= 0.3.0)

BUNDLED WITH
1.10.0
68 changes: 33 additions & 35 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,68 @@
class Blog < Sinatra::Application
end

class Post < ActiveRecord::Base

class Article < ActiveRecord::Base
def number_of_characters
self.text.length
end

end

get '/' do
@posts = Post.order("created_at DESC")
erb :"posts/index"
@articles = Article.order("created_at DESC")
erb :"articles/index"
end

get '/about' do
erb :"about/index"
end

# The New Post form sends a POST request (storing data) here
# where we try to create the post it sent in its params hash.
# If successful, redirect to that post. Otherwise, render the "posts/new"
# template where the @post object will have the incomplete data that the
# The New Article form sends a POST request (storing data) here
# where we try to create the article it sent in its params hash.
# If successful, redirect to that article. Otherwise, render the "posts/new"
# template where the @article object will have the incomplete data that the
# user can modify and resubmit.
post "/posts" do
@post = Post.new(params[:post])
if @post.save
post "/articles" do
@article = Article.new(params[:article])
if @article.save
redirect "/"
else
erb :"posts/new"
erb :"articles/new"
end
end

# Get the New Post form
get '/posts/new' do
@post = Post.new
erb :"posts/new"
# Get the New Article form
get '/articles/new' do
@article = Article.new
erb :"articles/new"
end

# Get the individual page of the post with this ID.
get "/posts/:id" do
@post = Post.find(params[:id])
erb :"posts/show"
# Get the individual page of the article with this ID.
get "/articles/:id" do
@article = Article.find(params[:id])
erb :"articles/show"
end

# Get the Edit Post form of the post with this ID.
get "/posts/:id/edit" do
@post = Post.find(params[:id])
erb :"posts/edit"
# Get the Edit Article form of the article with this ID.
get "/articles/:id/edit" do
@article = Article.find(params[:id])
erb :"articles/edit"
end

# The Edit Post form sends a PUT request (modifying data) here.
# If the post is updated successfully, redirect to it. Otherwise,
# render the edit form again with the failed @post object still in memory
# The Edit Article form sends a PUT request (modifying data) here.
# If the article is updated successfully, redirect to it. Otherwise,
# render the edit form again with the failed @article object still in memory
# so they can retry.
put "/posts/:id" do
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
put "/articles/:id" do
@article = Article.find(params[:id])
if @article.update_attributes(params[:article])
redirect "/"
else
erb :"posts/edit"
erb :"articles/edit"
end
end

# Deletes the post with this ID and redirects to homepage.
delete "/posts/:id" do
@post = Post.find(params[:id]).destroy
# Deletes the article with this ID and redirects to homepage.
delete "/articles/:id" do
@article = Article.find(params[:id]).destroy
redirect "/"
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreatePost < ActiveRecord::Migration
class CreateArticle < ActiveRecord::Migration
def change
create_table :posts do |t|
create_table :articles do |t|
t.string :title
t.text :text
t.timestamps
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

create_table "posts", force: true do |t|
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "text"
t.datetime "created_at"
Expand Down
44 changes: 44 additions & 0 deletions features/article.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Feature: Article

Background:
Given I have an article titled "An article about coffee" with the text "Lorem ipsum dolor samet"

Scenario: Accessing new article form
Given I am on the home page
When I follow "Create new article"
Then I should be on the create new article page
And I should see "New article"

Scenario: Creating an article
Given I am on the create new article page
When I fill in "article_title" with "My article title"
And I fill in "article_text" with "Lorem ipsum dolor samet"
And I press "Save"
Then I should be on the home page
And I should see "My article title"

Scenario: Showing an article
Given I am on the home page
When I follow "An article about coffee"
Then I should see "An article about coffee"
And I should see "Lorem ipsum dolor samet"

Scenario: Editing an article
Given I am on the home page
When I follow "Edit"
Then I should see "Edit - An article about coffee"
And I should see "Lorem ipsum dolor samet"
When I fill in "article_title" with "An article about Red Bull"
And I press "Update"
Then I should be on the home page
And I should see "An article about Red Bull"

Scenario: Deleting an article
Given I am editing an article titled "An article about coffee"
When I press "Delete"
Then I should be on the home page
And I should not see "My new article title"

Scenario: Show the number of characters used in article
Given I am on the home page
Then I should see the number of characters of the article displayed
44 changes: 0 additions & 44 deletions features/post.feature

This file was deleted.

14 changes: 7 additions & 7 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ def with_scope(locator)

# Own Steps

Given(/^I have a post titled "(.*?)" with the text "(.*?)"$/) do |arg1, arg2|
Post.create(title: arg1, text: arg2)
Given(/^I have an article titled "(.*?)" with the text "(.*?)"$/) do |arg1, arg2|
Article.create(title: arg1, text: arg2)
end


Given(/^I am editing a post titled "(.*?)"$/) do |post_title|
post = Post.find_by_title(post_title)
visit "/posts/#{post.id}/edit"
Given(/^I am editing an article titled "(.*?)"$/) do |article_title|
article = Article.find_by_title(article_title)
visit "/articles/#{article.id}/edit"
end

Then(/^I should see the number of characters of the post displayed$/) do
page.should have_xpath('//*', :text => Post.first.number_of_characters)
Then(/^I should see the number of characters of the article displayed$/) do
page.should have_xpath('//*', :text => Article.first.number_of_characters)
end

# end
Expand Down
Loading

0 comments on commit 42de4d0

Please sign in to comment.