diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 92dde1e0edd86ca3cc4fcb6e9356913117fabd0b..9309cc30d43cbc2fe25b2d3db1446cb8aac7bdd0 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -173,19 +173,6 @@ label { } } - /* if the user clicks the toggle button - -background colour is changed - -icon colour is changed - unfocus is sorted out in JQuery */ - &:focus { - border-color: $navbar-background; - background-color: $toggle-active-background; - - .icon-bar { - background-color: $hover-colour; - } - } - } diff --git a/app/assets/stylesheets/posts.scss b/app/assets/stylesheets/posts.scss index 6722a51f0c68cbb5ca9d7bc9f4e96bd6a7b66e10..0011063a78938c38da1760f48b2d0f692fba563b 100644 --- a/app/assets/stylesheets/posts.scss +++ b/app/assets/stylesheets/posts.scss @@ -143,6 +143,13 @@ h2.container { } } +/* +*/ +.form-group#category { + +} + + /* DESIGN FOR SMALL DEVICES */ diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3f713f724ff2a32b726dc2d3966f5115ec8a4785..e37a95b2976fc5bfb178a4f163727337a44e78bb 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,9 +1,8 @@ class PostsController < ApplicationController #runs the find_post method before the selected methods - before_action :find_post, only: [:show, :edit, :update, :destroy] + before_action :find_post, :check, only: [:show, :edit, :update, :destroy] before_action :authenticate_user!, only: [:edit, :destroy, :update, :new, :create, :request_contact] - before_action :must_make_account, :check, only: [:edit, :destoy, :update, :new, :create, :request_contact] - + before_action :must_make_account, only: [:edit, :destoy, :update, :new, :create, :request_contact] #Represents the index action #This will list all the posts depending on the selected category/query def index @@ -114,20 +113,22 @@ class PostsController < ApplicationController #Checks to see if the current user has set up a profile before the editing/creating/updating/deleting/contacting actions def must_make_account #Checks if profile is nil, ie hasnt been set up - unless current_user.profile==nil - flash[:notice] = t('.alertnew') - redirect_to post_path(@post) - return + if user_signed_in? + if current_user.profile==nil + flash[:notice] = t('.alertnew') + redirect_to post_path(@post) + return + end end #Gets redirected back to the post show page end - #Checks to see if the current user is the creator of the post before the editing/creating/updating/deleting/contacting actions + #Checks to see if the current user is the creator of the post before the editing/creating/updating/deleting/ actions def check unless current_user.id == @post.user_id - flash[:notice] = t('.alertupdate') + flash[:notice] = t('.alertno') redirect_to post_path(@post) - return + return end #Gets redirected back to the post show page end diff --git a/app/models/post.rb b/app/models/post.rb index f4fdbb2812bdb25330a92dd99ddea105ecc7aadc..4d4d9d491d585e9300c37449105d2b7240d009ac 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -16,6 +16,5 @@ class Post < ActiveRecord::Base message: "Enter valid postal code" } has_attached_file :post_image, styles: { post_index: "300x300>", post_show: "300x300>" }, default_url: "/images/:style/missing.png" - validates :post_image, :attachment_presence => true validates_attachment_content_type :post_image, content_type: /\Aimage\/.*\z/ end diff --git a/app/views/posts/_form.html.haml b/app/views/posts/_form.html.haml index 45f96e4722ad1f9376a4e3fe9688c07980af32fc..4c7cfee4352758752316b775622c57e37355f577 100644 --- a/app/views/posts/_form.html.haml +++ b/app/views/posts/_form.html.haml @@ -4,15 +4,25 @@ = f.input :post_image, input_html: {class: 'form-control'}, label: false = f.input :title,label: false, placeholder: t('.title') = f.input :description,label: false, placeholder: t('.description') - .form-group + .form-group#category = f.select :category_id, options_from_collection_for_select(Category.all, :id, :name), input_html: {class: "form-control"} = f.input :price,label: false, placeholder: t('.price') %h4= t('.contact') - = f.input :phone_number,label: false, placeholder: t('.number') - = f.input :city,label: false, placeholder: t('.city') - = f.input :address_one,label: false, placeholder: t('.address_one') - = f.input :address_two,label: false, placeholder: t('.address_two') - = f.input :address_three,label: false, placeholder: t('.address_three') - = f.input :postal_code,label: false, placeholder: t('.postal_code') - = f.button :submit, t('.submit') - + -# Displays the user's address from profile, only if the user is creating a new post, not editing + - if current_page?(controller: :posts, action: :new) + = f.input :phone_number,label: false, placeholder: t('.number'), input_html: {value: current_user.profile.number} + = f.input :city,label: false, placeholder: t('.city'), input_html: {value: current_user.profile.city} + = f.input :address_one,label: false, placeholder: t('.address_one'),input_html: {value: current_user.profile.address_one} + = f.input :address_two,label: false, placeholder: t('.address_two'), input_html: {value: current_user.profile.address_two} + = f.input :address_three,label: false, placeholder: t('.address_three'), input_html: {value: current_user.profile.address_three} + = f.input :postal_code,label: false, placeholder: t('.postal_code'), input_html: {value: current_user.profile.postal_code } + = f.button :submit, t('.submit') + - else + -# Displays the posts already existing address + = f.input :phone_number,label: false, placeholder: t('.number') + = f.input :city,label: false, placeholder: t('.city') + = f.input :address_one,label: false, placeholder: t('.address_one') + = f.input :address_two,label: false, placeholder: t('.address_two') + = f.input :address_three,label: false, placeholder: t('.address_three') + = f.input :postal_code,label: false, placeholder: t('.postal_code') + = f.button :submit, t('.editsubmit') diff --git a/config/locales/en.yml b/config/locales/en.yml index c51005485be3e37fb3be0d963d681749e0839deb..ba1f57951701b64592041a680d301d73ab5b797c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -73,13 +73,12 @@ en: address_three: Enter Address line three postal_code: Enter Postal code * submit: Publish Post + editsubmit: Pubilsh edited post contact : Add contact details edit: edited: Update Post title: Editing post... - alertedit: "You don't have permissions to edit this post!" - alertdestroy: "You don't have permissions to destroy this post!" - alertupdate: "You don't have permissions to update this post!" + alertno: "You don't have permissions to do this!" alertnew: "Set up your profile before creating a post" new: title: Create and publish your post! diff --git a/public/system/posts/post_images/000/000/048/original/goku.png b/public/system/posts/post_images/000/000/048/original/goku.png new file mode 100644 index 0000000000000000000000000000000000000000..dd2cd7043be2a54a84b3988c2c7365fd0225875b Binary files /dev/null and b/public/system/posts/post_images/000/000/048/original/goku.png differ diff --git a/public/system/posts/post_images/000/000/048/post_index/goku.png b/public/system/posts/post_images/000/000/048/post_index/goku.png new file mode 100644 index 0000000000000000000000000000000000000000..9c3585c68c12e52ee69bcce0fc26f53c9a9106b1 Binary files /dev/null and b/public/system/posts/post_images/000/000/048/post_index/goku.png differ diff --git a/public/system/posts/post_images/000/000/048/post_show/goku.png b/public/system/posts/post_images/000/000/048/post_show/goku.png new file mode 100644 index 0000000000000000000000000000000000000000..9c3585c68c12e52ee69bcce0fc26f53c9a9106b1 Binary files /dev/null and b/public/system/posts/post_images/000/000/048/post_show/goku.png differ diff --git a/public/system/posts/post_images/000/000/992/original/sample.jpg b/public/system/posts/post_images/000/000/992/original/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..26cd395b5ee0276ba3560f85a2e22b62ec0256de Binary files /dev/null and b/public/system/posts/post_images/000/000/992/original/sample.jpg differ diff --git a/public/system/posts/post_images/000/000/992/post_index/sample.jpg b/public/system/posts/post_images/000/000/992/post_index/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f4face207ee63793d701506cc103ab70d64cde9b Binary files /dev/null and b/public/system/posts/post_images/000/000/992/post_index/sample.jpg differ diff --git a/public/system/posts/post_images/000/000/992/post_show/sample.jpg b/public/system/posts/post_images/000/000/992/post_show/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f4face207ee63793d701506cc103ab70d64cde9b Binary files /dev/null and b/public/system/posts/post_images/000/000/992/post_show/sample.jpg differ diff --git a/public/system/posts/post_images/980/190/962/original/sample.jpg b/public/system/posts/post_images/980/190/962/original/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..26cd395b5ee0276ba3560f85a2e22b62ec0256de Binary files /dev/null and b/public/system/posts/post_images/980/190/962/original/sample.jpg differ diff --git a/public/system/posts/post_images/980/190/962/post_index/sample.jpg b/public/system/posts/post_images/980/190/962/post_index/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f4face207ee63793d701506cc103ab70d64cde9b Binary files /dev/null and b/public/system/posts/post_images/980/190/962/post_index/sample.jpg differ diff --git a/public/system/posts/post_images/980/190/962/post_show/sample.jpg b/public/system/posts/post_images/980/190/962/post_show/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f4face207ee63793d701506cc103ab70d64cde9b Binary files /dev/null and b/public/system/posts/post_images/980/190/962/post_show/sample.jpg differ diff --git a/test/controllers/posts_controller_test.rb b/test/controllers/posts_controller_test.rb index aabe0d98a15d9502e72b0faeeb2f9d32b351fcde..110f0f42d263e005a308cc3115731b6f65de54c8 100644 --- a/test/controllers/posts_controller_test.rb +++ b/test/controllers/posts_controller_test.rb @@ -4,10 +4,14 @@ class PostsControllerTest < ActionController::TestCase include Devise::Test::ControllerHelpers setup do - @post = posts(:one) @user = users(:three) #does not have a profile @user2 = users(:one) # does have a profile sign_in @user2 + + @category = categories(:one) + @post = posts(:one) + @post.post_image = File.new("test/fixtures/sample.jpg") + @post.save end #Get index posts form @@ -28,7 +32,7 @@ class PostsControllerTest < ActionController::TestCase assert_difference('Post.count') do post :create, post: @post.attributes end - assert_redirected_to post_path(assigns(:post)) + assert_redirected_to root_path end #Get show post form diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml index 37c150171ad5b8f5d73f2e2d47e2caba618d72ff..bd5863fafcb93a38d7b750fd01fb8b6ee5ebf31b 100644 --- a/test/fixtures/posts.yml +++ b/test/fixtures/posts.yml @@ -4,10 +4,11 @@ one: user: one title: MyString description: MyText + category: one price: £138.89 phone_number: 02083746279 address_one: test lane - address_two: + address_two: address_three: city: London postal_code: sw8 3ns @@ -23,3 +24,4 @@ two: address_three: city: London postal_code: sw3 3fs + category: one