resta_blog_engine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/blog/application.js +13 -0
  6. data/app/assets/javascripts/blog/articles.js +2 -0
  7. data/app/assets/stylesheets/blog/application.css +15 -0
  8. data/app/assets/stylesheets/blog/articles.css +4 -0
  9. data/app/assets/stylesheets/scaffold.css +56 -0
  10. data/app/controllers/blog/application_controller.rb +12 -0
  11. data/app/controllers/blog/articles_controller.rb +62 -0
  12. data/app/helpers/blog/application_helper.rb +4 -0
  13. data/app/helpers/blog/articles_helper.rb +4 -0
  14. data/app/models/blog/article.rb +4 -0
  15. data/app/models/blog/base.rb +5 -0
  16. data/app/views/blog/articles/_form.html.erb +25 -0
  17. data/app/views/blog/articles/edit.html.erb +6 -0
  18. data/app/views/blog/articles/index.html.erb +29 -0
  19. data/app/views/blog/articles/new.html.erb +5 -0
  20. data/app/views/blog/articles/show.html.erb +14 -0
  21. data/app/views/layouts/blog/application.html.erb +14 -0
  22. data/config/routes.rb +4 -0
  23. data/db/migrate/20160221152118_create_blog_articles.rb +10 -0
  24. data/lib/blog.rb +7 -0
  25. data/lib/blog/engine.rb +5 -0
  26. data/lib/blog/version.rb +3 -0
  27. data/lib/tasks/blog_tasks.rake +4 -0
  28. data/test/blog_test.rb +7 -0
  29. data/test/controllers/blog/articles_controller_test.rb +52 -0
  30. data/test/dummy/README.rdoc +28 -0
  31. data/test/dummy/Rakefile +6 -0
  32. data/test/dummy/app/assets/javascripts/application.js +13 -0
  33. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  34. data/test/dummy/app/controllers/application_controller.rb +5 -0
  35. data/test/dummy/app/helpers/application_helper.rb +2 -0
  36. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/test/dummy/bin/bundle +3 -0
  38. data/test/dummy/bin/rails +4 -0
  39. data/test/dummy/bin/rake +4 -0
  40. data/test/dummy/bin/setup +29 -0
  41. data/test/dummy/config.ru +4 -0
  42. data/test/dummy/config/application.rb +26 -0
  43. data/test/dummy/config/boot.rb +5 -0
  44. data/test/dummy/config/database.yml +25 -0
  45. data/test/dummy/config/environment.rb +5 -0
  46. data/test/dummy/config/environments/development.rb +41 -0
  47. data/test/dummy/config/environments/production.rb +79 -0
  48. data/test/dummy/config/environments/test.rb +42 -0
  49. data/test/dummy/config/initializers/assets.rb +11 -0
  50. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  52. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  53. data/test/dummy/config/initializers/inflections.rb +16 -0
  54. data/test/dummy/config/initializers/mime_types.rb +4 -0
  55. data/test/dummy/config/initializers/session_store.rb +3 -0
  56. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/test/dummy/config/locales/en.yml +23 -0
  58. data/test/dummy/config/routes.rb +4 -0
  59. data/test/dummy/config/secrets.yml +22 -0
  60. data/test/dummy/db/development.sqlite3 +0 -0
  61. data/test/dummy/db/migrate/20160221152546_create_blog_articles.blog.rb +11 -0
  62. data/test/dummy/db/schema.rb +23 -0
  63. data/test/dummy/log/development.log +11 -0
  64. data/test/dummy/public/404.html +67 -0
  65. data/test/dummy/public/422.html +67 -0
  66. data/test/dummy/public/500.html +66 -0
  67. data/test/dummy/public/favicon.ico +0 -0
  68. data/test/fixtures/blog/articles.yml +9 -0
  69. data/test/integration/navigation_test.rb +8 -0
  70. data/test/models/blog/article_test.rb +9 -0
  71. data/test/test_helper.rb +21 -0
  72. metadata +186 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c430944eb66e69de1f363cdb2be9f7b2e3ed091
4
+ data.tar.gz: 7335e1a32d5e633e7b1aadebd9ed5ccdcf075cd6
5
+ SHA512:
6
+ metadata.gz: 29d29c3c630770b685ff22a6113b3d806329159ab11728576a422f60d342c5b56e6b710133a0843f19a77a4f9886445b1386945eac546e778a39aa9e9f225057
7
+ data.tar.gz: ea9e5e8b61882d8a205711b78eb0f0aba7d939a3f962c9af19d566214848d0294cc0bc67bf5e5c1d61d2f837881034f9f5d5d98284247027db2bca95eb514081
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Truong Hoang Dung
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Blog
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Blog'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,12 @@
1
+ module Blog
2
+ class ApplicationController < ::AccountsController
3
+ before_action :set_account_connection
4
+
5
+ protected
6
+ def set_account_connection
7
+ if current_account and current_account.shard
8
+ ActiveRecord::Base.establish_connection current_account.shard.pg_url
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "blog/application_controller"
2
+
3
+ module Blog
4
+ class ArticlesController < ApplicationController
5
+ before_action :set_article, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /articles
8
+ def index
9
+ @articles = Article.all
10
+ end
11
+
12
+ # GET /articles/1
13
+ def show
14
+ end
15
+
16
+ # GET /articles/new
17
+ def new
18
+ @article = Article.new
19
+ end
20
+
21
+ # GET /articles/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /articles
26
+ def create
27
+ @article = Article.new(article_params)
28
+
29
+ if @article.save
30
+ redirect_to @article, notice: 'Article was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /articles/1
37
+ def update
38
+ if @article.update(article_params)
39
+ redirect_to @article, notice: 'Article was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /articles/1
46
+ def destroy
47
+ @article.destroy
48
+ redirect_to articles_url, notice: 'Article was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_article
54
+ @article = Article.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def article_params
59
+ params.require(:article).permit(:title, :text)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module Blog
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Blog
2
+ module ArticlesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Blog
2
+ class Article < Base
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module Blog
2
+ class Base < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@article) do |f| %>
2
+ <% if @article.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @article.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br>
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :text %><br>
20
+ <%= f.text_area :text %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @article %> |
6
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,29 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Listing Articles</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Title</th>
9
+ <th>Text</th>
10
+ <th colspan="3"></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @articles.each do |article| %>
16
+ <tr>
17
+ <td><%= article.title %></td>
18
+ <td><%= article.text %></td>
19
+ <td><%= link_to 'Show', article %></td>
20
+ <td><%= link_to 'Edit', edit_article_path(article) %></td>
21
+ <td><%= link_to 'Destroy', article, method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%= link_to 'New Article', new_article_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,14 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Title:</strong>
5
+ <%= @article.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Text:</strong>
10
+ <%= @article.text %>
11
+ </p>
12
+
13
+ <%= link_to 'Edit', edit_article_path(@article) %> |
14
+ <%= link_to 'Back', articles_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Blog</title>
5
+ <%= stylesheet_link_tag "blog/application", media: "all" %>
6
+ <%= javascript_include_tag "blog/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ Blog::Engine.routes.draw do
2
+ resources :articles
3
+ root 'articles#index'
4
+ end
@@ -0,0 +1,10 @@
1
+ class CreateBlogArticles < ActiveRecord::Migration
2
+ def change
3
+ create_table :blog_articles do |t|
4
+ t.string :title
5
+ t.text :text
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require "blog/engine"
2
+
3
+ module Blog
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Blog
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Blog
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Blog
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Blog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :blog do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BlogTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Blog
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ module Blog
4
+ class ArticlesControllerTest < ActionController::TestCase
5
+ setup do
6
+ @article = blog_articles(:one)
7
+ @routes = Engine.routes
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index
12
+ assert_response :success
13
+ assert_not_nil assigns(:articles)
14
+ end
15
+
16
+ test "should get new" do
17
+ get :new
18
+ assert_response :success
19
+ end
20
+
21
+ test "should create article" do
22
+ assert_difference('Article.count') do
23
+ post :create, article: { text: @article.text, title: @article.title }
24
+ end
25
+
26
+ assert_redirected_to article_path(assigns(:article))
27
+ end
28
+
29
+ test "should show article" do
30
+ get :show, id: @article
31
+ assert_response :success
32
+ end
33
+
34
+ test "should get edit" do
35
+ get :edit, id: @article
36
+ assert_response :success
37
+ end
38
+
39
+ test "should update article" do
40
+ patch :update, id: @article, article: { text: @article.text, title: @article.title }
41
+ assert_redirected_to article_path(assigns(:article))
42
+ end
43
+
44
+ test "should destroy article" do
45
+ assert_difference('Article.count', -1) do
46
+ delete :destroy, id: @article
47
+ end
48
+
49
+ assert_redirected_to articles_path
50
+ end
51
+ end
52
+ end