diff options
| author | mo khan <mo@mokhan.ca> | 2013-12-23 19:58:54 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-12-23 19:58:54 -0700 |
| commit | 05b447492b85beaf403d1d8b0b0f0a90bfbe4764 (patch) | |
| tree | d2df20ac72481cd49e6966417441298a77759897 | |
| parent | 2563273fc996a9f7bcd73c6fcb99d5047234ebe4 (diff) | |
| parent | 932189d517a4ce7efd6b1de0f2bc21185031dfef (diff) | |
Merge branch 'master' into vagrant
| -rw-r--r-- | .vimrc | 2 | ||||
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 9 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 3 | ||||
| -rw-r--r-- | app/controllers/favorites_controller.rb | 1 | ||||
| -rw-r--r-- | app/models/admin_user.rb | 8 | ||||
| -rw-r--r-- | app/models/category.rb | 1 | ||||
| -rw-r--r-- | app/models/creation.rb | 27 | ||||
| -rw-r--r-- | app/models/favorite.rb | 1 | ||||
| -rw-r--r-- | app/models/interest.rb | 1 | ||||
| -rw-r--r-- | app/models/photo.rb | 1 | ||||
| -rw-r--r-- | app/models/tutorial.rb | 3 | ||||
| -rw-r--r-- | app/models/user.rb | 2 | ||||
| -rw-r--r-- | app/services/dto/display_creation_dto.rb | 9 | ||||
| -rw-r--r-- | app/services/mappers/creation_to_display_creation_dto_mapper.rb | 13 | ||||
| -rw-r--r-- | app/services/queries/find_all_creations_query.rb | 12 | ||||
| -rw-r--r-- | app/views/layouts/_header.html.erb | 2 | ||||
| -rw-r--r-- | config/deploy.rb | 2 | ||||
| -rw-r--r-- | config/initializers/session_store.rb | 7 | ||||
| -rw-r--r-- | script/ci.sh | 4 | ||||
| -rw-r--r-- | spec/services/queries/find_all_creations_query_spec.rb | 22 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 6 |
22 files changed, 61 insertions, 76 deletions
diff --git a/.vimrc b/.vimrc deleted file mode 100644 index 6a322fb5..00000000 --- a/.vimrc +++ /dev/null @@ -1,2 +0,0 @@ -nmap ,t :w\|:!clear && script/test %<cr> -nmap ,ta :w\|:!script/test<cr> @@ -51,6 +51,7 @@ group :development, :test do gem 'simplecov' gem 'ffaker' gem 'selenium-webdriver' + gem 'poltergeist' end group :staging do diff --git a/Gemfile.lock b/Gemfile.lock index d3140525..308da7ac 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,7 +109,7 @@ GEM faye-websocket (0.4.7) eventmachine (>= 0.12.0) ffaker (1.16.2) - ffi (1.9.0) + ffi (1.9.3) fog (1.14.0) builder excon (~> 0.25.0) @@ -212,7 +212,7 @@ GEM rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) ruby-hmac (0.4.0) - rubyzip (0.9.9) + rubyzip (1.1.0) rvm-capistrano (1.4.1) capistrano (>= 2.0.0) sass (3.2.10) @@ -223,10 +223,10 @@ GEM sdoc (0.3.20) json (>= 1.1.3) rdoc (~> 3.10) - selenium-webdriver (2.35.1) + selenium-webdriver (2.39.0) childprocess (>= 0.2.5) multi_json (~> 1.0) - rubyzip (< 1.0.0) + rubyzip (~> 1.0) websocket (~> 1.0.4) simplecov (0.7.1) multi_json (~> 1.0) @@ -305,6 +305,7 @@ DEPENDENCIES lol_dba newrelic_rpm pg + poltergeist rack-mini-profiler rails (= 4.0.0) rmagick diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0db1df02..39476b91 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,9 +18,6 @@ class ApplicationController < ActionController::Base end def load_categories - #@categories = Rails.cache.fetch("categories-#{Category.count}") do - #Category.all - #end @categories = Category.all end diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 10052ddb..8ac00a75 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -22,6 +22,7 @@ class FavoritesController < ApplicationController end private + def find_creation @creation = Creation.find(params[:creation_id]) raise ActiveRecord::RecordNotFound unless @creation diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index 5a38533f..492d9a40 100644 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -1,9 +1,3 @@ class AdminUser < ActiveRecord::Base - # Include default devise modules. Others available are: - # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, - :recoverable, :rememberable, :trackable, :validatable - - # Setup accessible (or protected) attributes for your model - #attr_accessible :email, :password, :password_confirmation, :remember_me + devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable end diff --git a/app/models/category.rb b/app/models/category.rb index 2495135f..4ccdc9c8 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,6 +1,5 @@ class Category < ActiveRecord::Base has_and_belongs_to_many :creations, :join_table => 'creations_categories' - #attr_accessible :name, :slug default_scope -> { order(:name) } def to_param diff --git a/app/models/creation.rb b/app/models/creation.rb index 8f896af3..2e498df8 100644 --- a/app/models/creation.rb +++ b/app/models/creation.rb @@ -6,19 +6,14 @@ class Creation < ActiveRecord::Base has_many :favorites, :dependent => :destroy acts_as_taggable - default_scope -> { order("created_at DESC") } + default_scope -> { order(:created_at => :desc) } - # to be removed and moved to the DisplayCreationDTO def to_param "#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}" end def primary_image - if photos.any? - photos.first - else - Photo.new - end + photos.any? ? photos.first : Photo.new end def published? @@ -30,12 +25,7 @@ class Creation < ActiveRecord::Base end def add_photo(photo) - photos.create({:image => photo}) - end - - def self.search(query) - sql_search = "%#{query}%" - Creation.where("upper(name) like upper(?) OR upper(story) like upper(?)", sql_search, sql_search) + photos.create(:image => photo) end def is_liked_by(user) @@ -50,7 +40,14 @@ class Creation < ActiveRecord::Base end end - def self.visible_creations - Creation.includes(:user, :photos).where(:is_restricted => false).where('photos_count > 0').uniq + class << self + def search(query) + sql_search = "%#{query}%" + Creation.where("upper(name) like upper(?) OR upper(story) like upper(?)", sql_search, sql_search) + end + + def visible_creations + Creation.includes(:user, :photos).where(:is_restricted => false).where('photos_count > 0').uniq + end end end diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 51190099..6818820e 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -1,5 +1,4 @@ class Favorite < ActiveRecord::Base belongs_to :user belongs_to :creation, :counter_cache => true - #attr_accessible :user_id, :creation_id end diff --git a/app/models/interest.rb b/app/models/interest.rb index 54a8c850..a52286d4 100644 --- a/app/models/interest.rb +++ b/app/models/interest.rb @@ -1,3 +1,2 @@ class Interest < ActiveRecord::Base - #attr_accessible :name end diff --git a/app/models/photo.rb b/app/models/photo.rb index c77d2120..87e20c3c 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -1,5 +1,4 @@ class Photo < ActiveRecord::Base - #attr_accessible :is_primary, :creation, :image belongs_to :creation, :counter_cache => true validates :image, :presence => true mount_uploader :image, PhotoUploader diff --git a/app/models/tutorial.rb b/app/models/tutorial.rb index 4b9f498a..4e6456e5 100644 --- a/app/models/tutorial.rb +++ b/app/models/tutorial.rb @@ -1,11 +1,8 @@ class Tutorial < ActiveRecord::Base - #attr_accessible :description, :heading, :url, :image_url, :user_id, :author, :author_url validates :url, :presence => true belongs_to :user acts_as_taggable - #default_scope -> { order("created_at DESC") } - def to_param "#{id}-#{heading.gsub(/[^a-z0-9]+/i, '-')}" end diff --git a/app/models/user.rb b/app/models/user.rb index f892b6db..2ae299f6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,11 +10,9 @@ class User < ActiveRecord::Base validates :name, :presence => true validates :website, :format => URI::regexp(%w(http https)), :allow_blank => true devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable - #attr_accessible :name, :email, :website, :twitter, :facebook, :city, :latitude, :longitude, :password, :password_confirmation, :current_password, :remember_me, :interest_ids has_many :creations, :dependent => :destroy has_many :favorites, :dependent => :destroy has_many :tutorials, :dependent => :destroy - #has_and_belongs_to_many :interests, :join_table => 'users_interests', uniq: true, :autosave => true has_and_belongs_to_many :interests, :join_table => 'users_interests', :autosave => true has_one :avatar acts_as_tagger diff --git a/app/services/dto/display_creation_dto.rb b/app/services/dto/display_creation_dto.rb deleted file mode 100644 index b80b70d2..00000000 --- a/app/services/dto/display_creation_dto.rb +++ /dev/null @@ -1,9 +0,0 @@ -class DisplayCreationDTO - attr_accessor :id, :name, :story, :primary_image, :thumb_url, :user, :favorites - def self.model_name - ActiveModel::Name.new(self, nil, 'Creation') - end - def to_param - "#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}" - end -end diff --git a/app/services/mappers/creation_to_display_creation_dto_mapper.rb b/app/services/mappers/creation_to_display_creation_dto_mapper.rb deleted file mode 100644 index efa41c29..00000000 --- a/app/services/mappers/creation_to_display_creation_dto_mapper.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreationToDisplayCreationDTOMapper - def map_from(creation) - dto = DisplayCreationDTO.new - dto.id = creation.id - dto.name = creation.name - dto.story = creation.story - dto.primary_image = creation.primary_image - dto.thumb_url = creation.primary_image.image.thumb.url - dto.user = creation.user - dto.favorites = creation.favorites - dto - end -end diff --git a/app/services/queries/find_all_creations_query.rb b/app/services/queries/find_all_creations_query.rb index acb8bbfe..f67ca694 100644 --- a/app/services/queries/find_all_creations_query.rb +++ b/app/services/queries/find_all_creations_query.rb @@ -1,15 +1,9 @@ class FindAllCreationsQuery - def initialize(mapper = CreationToDisplayCreationDTOMapper.new) - @mapper = mapper + def initialize(repository = Creation) + @repository = repository end def fetch(params) - find_creations.page(params[:page]).per(9) - end - - private - - def find_creations - Creation.includes(:user, :photos).where(:is_restricted => false).where('photos_count > 0').uniq + @repository.visible_creations.page(params[:page]).per(9) end end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 9f1c2a07..84d8aa0d 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -13,9 +13,11 @@ <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Categories<b class="caret"></b></a> <ul class="dropdown-menu"> + <% cache @categories do %> <% @categories.each do |category| %> <li><%= link_to category.name, category_path(category) %></li> <% end %> + <% end %> </ul> </li> </ul> diff --git a/config/deploy.rb b/config/deploy.rb index c887ee9c..73c6d4a7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -22,7 +22,7 @@ default_run_options[:pty] = true # password prompt # git set :scm, :git set :scm_verbose, true -set :repository, "git@bitbucket.org:mocheen/cakeside.git" +set :repository, "git@bitbucket.org:cakeside/cakeside.git" set :branch, "master" set :deploy_via, :remote_cache diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 206091a2..9558df5c 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,6 @@ # Be sure to restart your server when you modify this file. - -Cake::Application.config.session_store :cookie_store, key: '_cake_eater' +configuration = { + key: '_cake_eater', + expire_after: 1.day +} +Cake::Application.config.session_store ActionDispatch::Session::CacheStore, configuration diff --git a/script/ci.sh b/script/ci.sh index a5ae2727..fdb071f6 100644 --- a/script/ci.sh +++ b/script/ci.sh @@ -4,9 +4,9 @@ echo "load bashrc" [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" echo 'switch gemset' -rvm use ruby-2.0.0-p247@cakeside --create +rvm use ruby-2.0.0-p353@cakeside --create echo 'bundle install' bundle install --without production cp config/database.yml.example config/database.yml -xvfb-run bundle exec rake ci --trace +bundle exec rake ci --trace diff --git a/spec/services/queries/find_all_creations_query_spec.rb b/spec/services/queries/find_all_creations_query_spec.rb new file mode 100644 index 00000000..be36c437 --- /dev/null +++ b/spec/services/queries/find_all_creations_query_spec.rb @@ -0,0 +1,22 @@ +require "spec_helper" + +describe FindAllCreationsQuery do + let(:sut) { FindAllCreationsQuery.new } + let(:results) { sut.fetch({}) } + + let!(:cake_with_a_photo) { create(:creation, photos: [create(:photo)]) } + let!(:cake_without_a_photo) { create(:creation, photos: []) } + let!(:restricted_cake) { create(:creation, is_restricted: true, photos: [create(:photo)]) } + + it "returns all creations with at least one photo" do + results.should include(cake_with_a_photo) + end + + it "ignores cakes without a photo" do + results.should_not include(cake_without_a_photo) + end + + it "ignores restricted cakes" do + results.should_not include(restricted_cake) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7d900854..aa749f81 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,9 +7,15 @@ require 'rspec/rails' require 'rspec/autorun' require 'capybara/rails' require 'capybara/rspec' +require 'capybara/poltergeist' require 'ffaker' require 'database_cleaner' +Capybara.register_driver :poltergeist do |app| + Capybara::Poltergeist::Driver.new(app, {:timeout => 60}) +end +Capybara.javascript_driver = :poltergeist + Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.mock_with :rspec |
