From 8dc3352761fdc98b0c6b0bed3717ab20e51693d3 Mon Sep 17 00:00:00 2001 From: enterteg Date: Wed, 23 Mar 2016 14:33:33 +0100 Subject: [PATCH] added post controller --- Gemfile | 5 +- Gemfile.lock | 16 +++- app/assets/javascripts/posts.coffee | 7 ++ app/assets/javascripts/public.coffee.erb | 1 + app/assets/javascripts/session.coffee | 3 + app/assets/stylesheets/mixins.sass | 2 + app/assets/stylesheets/posts.scss | 3 + app/assets/stylesheets/public.sass | 77 ++++++++++++++++--- app/assets/stylesheets/session.scss | 3 + app/controllers/application_controller.rb | 10 +++ app/controllers/posts_controller.rb | 53 +++++++++++++ app/controllers/public_controller.rb | 4 + app/controllers/session_controller.rb | 22 ++++++ app/helpers/application_helper.rb | 1 + app/helpers/posts_helper.rb | 2 + app/helpers/session_helper.rb | 2 + app/models/category.rb | 3 + app/models/photo.rb | 3 + app/models/post.rb | 8 ++ app/models/user.rb | 3 + app/views/layouts/application.html.erb | 15 ---- app/views/layouts/application.html.haml | 48 ++++++++++++ app/views/partials/_map.html.haml | 4 + app/views/posts/_form.html.haml | 7 ++ app/views/posts/edit.html.erb | 2 + app/views/posts/new.html.haml | 1 + app/views/posts/update_form.js.erb | 14 ++++ app/views/public/_flag.html.haml | 3 - app/views/public/index.html.haml | 39 +++------- app/views/session/new.html.haml | 4 + config/application.rb | 1 + config/routes.rb | 9 ++- .../20160322153130_create_categories.rb | 8 ++ db/migrate/20160322153524_create_posts.rb | 13 ++++ db/migrate/20160322153954_create_photos.rb | 9 +++ db/migrate/20160322161631_create_users.rb | 9 +++ db/schema.rb | 53 +++++++++++++ test/controllers/posts_controller_test.rb | 24 ++++++ test/controllers/session_controller_test.rb | 7 ++ test/fixtures/categories.yml | 7 ++ test/fixtures/photos.yml | 9 +++ test/fixtures/posts.yml | 15 ++++ test/fixtures/users.yml | 9 +++ test/models/category_test.rb | 7 ++ test/models/photo_test.rb | 7 ++ test/models/post_test.rb | 7 ++ test/models/user_test.rb | 7 ++ 47 files changed, 505 insertions(+), 61 deletions(-) create mode 100644 app/assets/javascripts/posts.coffee create mode 100644 app/assets/javascripts/session.coffee create mode 100644 app/assets/stylesheets/posts.scss create mode 100644 app/assets/stylesheets/session.scss create mode 100644 app/controllers/posts_controller.rb create mode 100644 app/controllers/session_controller.rb create mode 100644 app/helpers/posts_helper.rb create mode 100644 app/helpers/session_helper.rb create mode 100644 app/models/category.rb create mode 100644 app/models/photo.rb create mode 100644 app/models/post.rb create mode 100644 app/models/user.rb delete mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/application.html.haml create mode 100644 app/views/partials/_map.html.haml create mode 100644 app/views/posts/_form.html.haml create mode 100644 app/views/posts/edit.html.erb create mode 100644 app/views/posts/new.html.haml create mode 100644 app/views/posts/update_form.js.erb delete mode 100644 app/views/public/_flag.html.haml create mode 100644 app/views/session/new.html.haml create mode 100644 db/migrate/20160322153130_create_categories.rb create mode 100644 db/migrate/20160322153524_create_posts.rb create mode 100644 db/migrate/20160322153954_create_photos.rb create mode 100644 db/migrate/20160322161631_create_users.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/posts_controller_test.rb create mode 100644 test/controllers/session_controller_test.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/fixtures/photos.yml create mode 100644 test/fixtures/posts.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/category_test.rb create mode 100644 test/models/photo_test.rb create mode 100644 test/models/post_test.rb create mode 100644 test/models/user_test.rb diff --git a/Gemfile b/Gemfile index 4b64cac..449f5ee 100644 --- a/Gemfile +++ b/Gemfile @@ -23,8 +23,9 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' -gem 'haml' +gem 'bcrypt', '~> 3.1.7' +gem 'haml', '~> 4.0', '>= 4.0.7' +gem 'paperclip', '~> 4.3', '>= 4.3.6' # Use Unicorn as the app server # gem 'unicorn' diff --git a/Gemfile.lock b/Gemfile.lock index a14efca..f137d61 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,10 +37,15 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + bcrypt (3.1.11) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) byebug (8.2.2) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.8) + climate_control (>= 0.0.3, < 1.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -70,11 +75,18 @@ GEM mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.99.1) + mimemagic (0.3.0) mini_portile2 (2.0.0) minitest (5.8.4) multi_json (1.11.2) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) + paperclip (4.3.6) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + cocaine (~> 0.5.5) + mime-types + mimemagic (= 0.3.0) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -144,11 +156,13 @@ PLATFORMS ruby DEPENDENCIES + bcrypt (~> 3.1.7) byebug coffee-rails (~> 4.1.0) - haml + haml (~> 4.0, >= 4.0.7) jbuilder (~> 2.0) jquery-rails + paperclip (~> 4.3, >= 4.3.6) rails (= 4.2.6) sass-rails (~> 5.0) sdoc (~> 0.4.0) diff --git a/app/assets/javascripts/posts.coffee b/app/assets/javascripts/posts.coffee new file mode 100644 index 0000000..43a6dbb --- /dev/null +++ b/app/assets/javascripts/posts.coffee @@ -0,0 +1,7 @@ +$ -> + $('#post_category_id').on 'change', -> + $.ajax 'update_form', + type: 'POST', + data: { + category_id: $('#post_category_id option:selected').val() + } diff --git a/app/assets/javascripts/public.coffee.erb b/app/assets/javascripts/public.coffee.erb index 43bd8c1..4640a7b 100644 --- a/app/assets/javascripts/public.coffee.erb +++ b/app/assets/javascripts/public.coffee.erb @@ -4,6 +4,7 @@ $(document).ready -> refresh_pin() ) + refresh_pin = -> $('#location_pin').remove() $('#map_photo').off('click') diff --git a/app/assets/javascripts/session.coffee b/app/assets/javascripts/session.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/session.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/mixins.sass b/app/assets/stylesheets/mixins.sass index f44f8b7..0d8a2a9 100644 --- a/app/assets/stylesheets/mixins.sass +++ b/app/assets/stylesheets/mixins.sass @@ -7,6 +7,8 @@ @content @keyframes $name @content +=animation($anime) + -webkit-animation: $anime =transform($transforms) -moz-transform: $transforms diff --git a/app/assets/stylesheets/posts.scss b/app/assets/stylesheets/posts.scss new file mode 100644 index 0000000..ed4dfd1 --- /dev/null +++ b/app/assets/stylesheets/posts.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Posts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/public.sass b/app/assets/stylesheets/public.sass index 0228d78..5e5831f 100644 --- a/app/assets/stylesheets/public.sass +++ b/app/assets/stylesheets/public.sass @@ -1,5 +1,6 @@ @import 'mixins' +$button-color: rgba(150,0,250,0.1) $top_menu_height: 80px body margin: 0 @@ -7,10 +8,10 @@ body font-family: 'Roboto', sans-serif font-size: 16px .container - max-width: 1100px + max-width: 1000px margin: 0 auto background: white - + padding: 0px 10px #top_menu float: left height: $top_menu_height @@ -23,24 +24,49 @@ body float: left margin: 0px 15px ul + color: rgba(250,20,250,1) padding: 0px margin: 0px line-height: $top_menu_height float: left list-style-type: none li - position: relative - font-size: 1.2rem + color: black + font-size: 1.3rem display: inline margin: 0px 2px padding: 3px 5px - border: 0px solid white - +transition(0.2s ease all) - top: 0px + border-top: 0px solid white + +transition(0.5s border) &:hover - top: -2px - border-bottom: 0.5px solid #ccc + position: relative cursor: pointer + border-top: 30px solid rgba(150,0,200,0.1) + .admin + float: right + line-height: $top_menu_height + .button + border-radius: 7px + margin-left: 5px + padding: 7px 15px + text-decoration: none + color: #555 + +transition(0.3s ease all) + background-color: rgba(150,0,150,0.05) + &:hover + background-color: rgba(140,0,150,0.1) + color: #333 + &.logout + outline: none + background-color: transparent + padding: 0px + font-size: 0.9e + padding: 5px 10px + border-bottom: 1px solid white + &:hover + border-bottom: 1px solid #ccc + + .social float: right height: $top_menu_height @@ -60,6 +86,35 @@ body &:hover opacity: 0.7 +section + margin: 100px 0px + .post + max-width: 600px + margin: 0 auto + font-family: 'Raleway' + header + margin-left: 10px + font-size: 2rem + footer + font-size: 0.9rem + line-height: 2 + &:before + content: '' + width: 80% + height: 1px + display: inline-block + background: #ccc + position: relative + top: -4px + margin-right: 10px + article + + font-weigth: 200 + padding: 15px 10px + width: 90% + text-align: justify + line-height: 1.4 + font-size: 1.2rem #logo_banner clear: both @@ -84,6 +139,9 @@ body .bigger letter-spacing: 5px font-size: 5rem + + + //--------- map styles #refresh_pin_button @@ -99,7 +157,6 @@ body z-index: 1 img width: 100% - height: 100% .map_pin position: absolute width: 20px diff --git a/app/assets/stylesheets/session.scss b/app/assets/stylesheets/session.scss new file mode 100644 index 0000000..6fa5e44 --- /dev/null +++ b/app/assets/stylesheets/session.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the session controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..133a997 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,14 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + +private + def current_user + @current_user ||= User.find(session[:user_id]) if session[:user_id] + end + helper_method :current_user + + def authenticate_user + redirect_to login_path if current_user.nil? + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..68cc913 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,53 @@ +class PostsController < ApplicationController + before_action :find_post, only: [:show, :edit, :update, :destroy] + + def new + @post = Post.new + end + + def create + @post = Post.new(post_params) + if @post.save + redirect_to @post, notice: 'Post created successfully' + else + flash.now.notice = 'Some errors occured, cannot create post.' + render :new + end + end + + def show + end + def edit + end + + def update + if @post.update(post_params) + redirect_to @post, notice: 'Post updated successfully' + else + flash.now.notice = 'Some errors occured, cannot update post.' + render :edit + end + end + + def destroy + if @post.destroy + redirect_to :root, notice: 'Post deleted successfully' + else + redirect_to @post, notice: 'Cannot delete post, some errors occured' + end + end + def update_form + @category_id = params[:category_id] + + respond_to do |format| + format.js + end + end +private + def find_post + @post = Post.find(params[:id]) + end + def post_params + params.require(:post).permit(:title,:desc,:category_id) + end +end diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb index 2d7105b..bddf677 100644 --- a/app/controllers/public_controller.rb +++ b/app/controllers/public_controller.rb @@ -1,4 +1,8 @@ class PublicController < ApplicationController def index end + + def stats + + end end diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb new file mode 100644 index 0000000..6e6c245 --- /dev/null +++ b/app/controllers/session_controller.rb @@ -0,0 +1,22 @@ +class SessionController < ApplicationController + def new + redirect_to :root if current_user + end + + def create + reset_session + user = User.find_by(login: params[:login]) + if user && user.authenticate(params[:password]) + session[:user_id] = user.id + redirect_to :root + else + flash.now.notice = 'Invalid login or password' + render :new + end + end + + def destroy + reset_session + redirect_to :root + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..6e9e2fe 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,3 @@ module ApplicationHelper + end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 0000000..a7b8cec --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,2 @@ +module PostsHelper +end diff --git a/app/helpers/session_helper.rb b/app/helpers/session_helper.rb new file mode 100644 index 0000000..f867f86 --- /dev/null +++ b/app/helpers/session_helper.rb @@ -0,0 +1,2 @@ +module SessionHelper +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..b77c95c --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,3 @@ +class Category < ActiveRecord::Base + has_many :posts +end diff --git a/app/models/photo.rb b/app/models/photo.rb new file mode 100644 index 0000000..c66dba1 --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,3 @@ +class Photo < ActiveRecord::Base + belongs_to :post +end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 0000000..8c12cb5 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,8 @@ +class Post < ActiveRecord::Base + belongs_to :category + has_many :photos + + validates_presence_of :title, :desc, :category_id + validates :desc, length: { minimum: 100} + validates :title, length: { minimum: 3} +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..3af0f7e --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ActiveRecord::Base + has_secure_password +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index ec10c0b..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,15 +0,0 @@ - - - - Blog - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..0911ead --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,48 @@ +%html + %head + %title Blog + = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true + = javascript_include_tag 'application', 'data-turbolinks-track' => true + %link{:href => "https://fonts.googleapis.com/css?family=Raleway:200|Roboto:100", :rel => "stylesheet", :type => "text/css"}/ + = csrf_meta_tags + %body + %header + .container + #top_menu + %nav + =link_to :root do + #logo_image + %ul + %li= 'my life' + | + %li= 'travels' + | + %li= 'food' + | + %li= 'about me' + .right + -if current_user + .admin + =link_to '+ Add post', new_post_path, class: 'button add_post' + =link_to 'Statistics', stats_path, class: 'button stats' + =link_to 'Logout', logout_path, class: 'button logout' + - else + .social + =link_to 'fb-profile' do + =image_tag 'fb-icon.png' + =link_to 'gmail' do + =image_tag 'gmail-icon.png' + #logo_banner + .banner_text + .smaller + = 'OPEN THE DOOR' + %br/ + .smaller_more + = 'TO MY' + %br/ + .bigger + = 'DREAMS' + - if flash[:notice] + = flash[:notice] + .container + = yield \ No newline at end of file diff --git a/app/views/partials/_map.html.haml b/app/views/partials/_map.html.haml new file mode 100644 index 0000000..8ab04ca --- /dev/null +++ b/app/views/partials/_map.html.haml @@ -0,0 +1,4 @@ +#map_form + #refresh_pin_button Resetuj flage + #map_photo + = image_tag 'map.jpg' \ No newline at end of file diff --git a/app/views/posts/_form.html.haml b/app/views/posts/_form.html.haml new file mode 100644 index 0000000..ff07384 --- /dev/null +++ b/app/views/posts/_form.html.haml @@ -0,0 +1,7 @@ +=form_for @post do |f| + = f.label :title + = f.text_field :title + = f.label :category_id + = f.select :category_id, [['travels', 1], ['food', 2], ['my life', 3]], prompt: '- select category -' + = f.label :desc, 'Content' + = f.text_area :desc diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb new file mode 100644 index 0000000..7007fc5 --- /dev/null +++ b/app/views/posts/edit.html.erb @@ -0,0 +1,2 @@ +

Posts#edit

+

Find me in app/views/posts/edit.html.erb

diff --git a/app/views/posts/new.html.haml b/app/views/posts/new.html.haml new file mode 100644 index 0000000..86842fe --- /dev/null +++ b/app/views/posts/new.html.haml @@ -0,0 +1 @@ += render 'form' \ No newline at end of file diff --git a/app/views/posts/update_form.js.erb b/app/views/posts/update_form.js.erb new file mode 100644 index 0000000..dc7fa6c --- /dev/null +++ b/app/views/posts/update_form.js.erb @@ -0,0 +1,14 @@ +<% if @category_id.to_i == 1 %> + $('#new_post').append('<%= j render 'partials/map' %>') +<% else %> + $('#map_form').remove() +<% end %> + + + + + + + + + diff --git a/app/views/public/_flag.html.haml b/app/views/public/_flag.html.haml deleted file mode 100644 index 3306fac..0000000 --- a/app/views/public/_flag.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -#refresh_pin_button Resetuj flage -#map_photo - = image_tag 'map.jpg' \ No newline at end of file diff --git a/app/views/public/index.html.haml b/app/views/public/index.html.haml index a121385..9ac786f 100644 --- a/app/views/public/index.html.haml +++ b/app/views/public/index.html.haml @@ -1,29 +1,10 @@ -%header - .container - #top_menu - %nav - =link_to :root do - #logo_image - %ul - %li= 'my life' - | - %li= 'travels' - | - %li= 'food' - | - %li= 'about me' - .social - =link_to 'fb-profile' do - =image_tag 'fb-icon.png' - =link_to 'gmail' do - =image_tag 'gmail-icon.png' - #logo_banner - .banner_text - .smaller - = 'OPEN THE DOOR' - %br/ - .smaller_more - = 'TO MY' - %br/ - .bigger - = 'DREAMS' \ No newline at end of file +%section + .post + %header= 'First post is the hardest one' + %footer= '24/03/2016' + %article + Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + %br/ + %br/ + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + =render 'partials/map' \ No newline at end of file diff --git a/app/views/session/new.html.haml b/app/views/session/new.html.haml new file mode 100644 index 0000000..01ef235 --- /dev/null +++ b/app/views/session/new.html.haml @@ -0,0 +1,4 @@ +=form_tag login_path do + = text_field_tag :login + = password_field_tag :password + = submit_tag 'Log in' \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index ecd54d7..c43cd71 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,5 +22,6 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + config.force_ssl = true end end diff --git a/config/routes.rb b/config/routes.rb index 929d9c6..d8ecd17 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,11 @@ Rails.application.routes.draw do - get 'public/index' + + post 'posts/update_form' + post 'login' => 'session#create', as: :login + get 'logout' => 'session#destroy', as: :logout + get 'login' => 'session#new' + get 'stats' => 'public#stats', as: :stats + resources :posts + root 'public#index' end diff --git a/db/migrate/20160322153130_create_categories.rb b/db/migrate/20160322153130_create_categories.rb new file mode 100644 index 0000000..4b0ff05 --- /dev/null +++ b/db/migrate/20160322153130_create_categories.rb @@ -0,0 +1,8 @@ +class CreateCategories < ActiveRecord::Migration + def change + create_table :categories do |t| + t.string :name + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160322153524_create_posts.rb b/db/migrate/20160322153524_create_posts.rb new file mode 100644 index 0000000..d44f6b4 --- /dev/null +++ b/db/migrate/20160322153524_create_posts.rb @@ -0,0 +1,13 @@ +class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + t.string :title + t.text :desc + t.integer :category_id + t.integer :locX + t.integer :locY + t.timestamps null: false + end + add_index :posts, :category_id + end +end diff --git a/db/migrate/20160322153954_create_photos.rb b/db/migrate/20160322153954_create_photos.rb new file mode 100644 index 0000000..aedff72 --- /dev/null +++ b/db/migrate/20160322153954_create_photos.rb @@ -0,0 +1,9 @@ +class CreatePhotos < ActiveRecord::Migration + def change + create_table :photos do |t| + t.references :post, index: true, foreign_key: true + t.attachment :photo + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160322161631_create_users.rb b/db/migrate/20160322161631_create_users.rb new file mode 100644 index 0000000..24f3e56 --- /dev/null +++ b/db/migrate/20160322161631_create_users.rb @@ -0,0 +1,9 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :login + t.string :password_digest + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..21f6fdc --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,53 @@ +# encoding: UTF-8 +# 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: 20160322161631) do + + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "photos", force: :cascade do |t| + t.integer "post_id" + t.string "photo_file_name" + t.string "photo_content_type" + t.integer "photo_file_size" + t.datetime "photo_updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "photos", ["post_id"], name: "index_photos_on_post_id" + + create_table "posts", force: :cascade do |t| + t.string "title" + t.text "desc" + t.integer "category_id" + t.integer "locX" + t.integer "locY" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "posts", ["category_id"], name: "index_posts_on_category_id" + + create_table "users", force: :cascade do |t| + t.string "login" + t.string "password_digest" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/posts_controller_test.rb b/test/controllers/posts_controller_test.rb new file mode 100644 index 0000000..8b645fb --- /dev/null +++ b/test/controllers/posts_controller_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + test "should get new" do + get :new + assert_response :success + end + + test "should get create" do + get :create + assert_response :success + end + + test "should get edit" do + get :edit + assert_response :success + end + + test "should get destroyupdate" do + get :destroyupdate + assert_response :success + end + +end diff --git a/test/controllers/session_controller_test.rb b/test/controllers/session_controller_test.rb new file mode 100644 index 0000000..da49ba4 --- /dev/null +++ b/test/controllers/session_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SessionControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000..56066c6 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/fixtures/photos.yml b/test/fixtures/photos.yml new file mode 100644 index 0000000..265ca7b --- /dev/null +++ b/test/fixtures/photos.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + post_id: + attachment: + +two: + post_id: + attachment: diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml new file mode 100644 index 0000000..6fd262d --- /dev/null +++ b/test/fixtures/posts.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + desc: MyText + references: + locX: 1 + locY: 1 + +two: + title: MyString + desc: MyText + references: + locX: 1 + locY: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..69804eb --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + login: MyString + password: + +two: + login: MyString + password: diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000..4733541 --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/photo_test.rb b/test/models/photo_test.rb new file mode 100644 index 0000000..e2ec03a --- /dev/null +++ b/test/models/photo_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PhotoTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/post_test.rb b/test/models/post_test.rb new file mode 100644 index 0000000..6d9d463 --- /dev/null +++ b/test/models/post_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end