summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo.khan@gmail.com>2014-07-07 22:31:57 -0600
committermo k <mo.khan@gmail.com>2014-07-07 22:31:57 -0600
commit99cff553c24c9ea7be07a86e99dbf37b501cbbce (patch)
tree80aaa789ccf5dff181cc17e7dc80861b0bf9d373
parent01c7ed283d90effb6fb6b360d0ba1cc5055fa2ed (diff)
parent4ca198d30d21394869756182d7d258f9edd22217 (diff)
Merged in mocheen/cakeside/backbone-testing (pull request #73)
remove old rails creations/photos pages and unused javascript code.
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock4
-rw-r--r--app/assets/javascripts/application.js1
-rw-r--r--app/assets/javascripts/backbone/views/cakes/index_view.js.coffee5
-rw-r--r--app/assets/javascripts/backbone/views/cakes/no_cakes_view.js.coffee5
-rw-r--r--app/assets/javascripts/creations.js4
-rw-r--r--app/assets/javascripts/masonry.js.coffee1
-rw-r--r--app/assets/javascripts/users_edit.js37
-rw-r--r--app/assets/javascripts/utility/greeting.js.coffee8
-rw-r--r--app/assets/stylesheets/application.css.scss1
-rw-r--r--app/controllers/creations_controller.rb52
-rw-r--r--app/controllers/my/photos_controller.rb44
-rw-r--r--app/models/comment.rb2
-rw-r--r--app/services/application/photo_to_jq_json_mapper.rb11
-rw-r--r--app/services/application/upload_photo.rb11
-rw-r--r--app/views/creations/_form.html.erb53
-rw-r--r--app/views/creations/edit.html.erb16
-rw-r--r--app/views/creations/index.html.erb3
-rw-r--r--app/views/creations/new.html.erb8
-rw-r--r--app/views/creations/show.html.erb6
-rw-r--r--app/views/layouts/_header.html.erb4
-rw-r--r--app/views/my/photos/_form.html.erb89
-rw-r--r--app/views/my/photos/new.html.erb8
-rw-r--r--app/views/my/settings/index.html.erb5
-rw-r--r--app/views/tutorials/index.html.erb3
-rw-r--r--config/routes.rb10
-rw-r--r--spec/controllers/creations_controller_spec.rb108
-rw-r--r--spec/controllers/my/photos_controller_spec.rb64
-rw-r--r--spec/javascripts/backbone/models/cake_spec.js.coffee40
-rw-r--r--spec/javascripts/backbone/views/cake_view_spec.js.coffee15
-rw-r--r--spec/javascripts/utility/greeting_spec.js16
-rw-r--r--spec/routing/creations_routing_spec.rb21
32 files changed, 77 insertions, 579 deletions
diff --git a/Gemfile b/Gemfile
index d0d7cf5a..124f6afb 100644
--- a/Gemfile
+++ b/Gemfile
@@ -22,7 +22,6 @@ gem 'acts-as-taggable-on', '~> 2.4.1'
gem 'delayed_job', "~> 4.0.0"
gem 'delayed_job_active_record', "~> 4.0.0"
gem 'daemons', '~> 1.1.9'
-gem 'jquery-fileupload-rails', '~> 0.4.1'
gem 'dotenv-rails'
gem 'pg'
gem 'asset_sync', '~> 1.0.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 9a5713c2..de3a7253 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -158,9 +158,6 @@ GEM
jbuilder (1.5.3)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
- jquery-fileupload-rails (0.4.1)
- actionpack (>= 3.1)
- railties (>= 3.1)
jquery-rails (3.1.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
@@ -351,7 +348,6 @@ DEPENDENCIES
foreman
gibbon (~> 1.1.2)
jbuilder (~> 1.2)
- jquery-fileupload-rails (~> 0.4.1)
jquery-rails
jquery-ui-rails (~> 4.0.0)
js-routes (~> 0.9.8)
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 1bee516a..2d87213c 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -16,7 +16,6 @@
//= require jquery.ui.all
//= require jquery.validate
//= require jquery.masonry
-//= require jquery-fileupload
//= require jquery.embedly
//= require tag-it
//= require bootstrap
diff --git a/app/assets/javascripts/backbone/views/cakes/index_view.js.coffee b/app/assets/javascripts/backbone/views/cakes/index_view.js.coffee
index 527ab960..b410fb06 100644
--- a/app/assets/javascripts/backbone/views/cakes/index_view.js.coffee
+++ b/app/assets/javascripts/backbone/views/cakes/index_view.js.coffee
@@ -1,9 +1,6 @@
+#= require backbone/views/cakes/no_cakes_view
CakeSide.Views.Cakes ||= {}
-class CakeSide.Views.Cakes.NoCakesView extends Marionette.ItemView
- template: JST["backbone/templates/cakes/no_cakes"]
- tagName: 'li'
-
class CakeSide.Views.Cakes.IndexView extends Marionette.CollectionView
childView: CakeSide.Views.Cakes.CakeView
emptyView: CakeSide.Views.Cakes.NoCakesView
diff --git a/app/assets/javascripts/backbone/views/cakes/no_cakes_view.js.coffee b/app/assets/javascripts/backbone/views/cakes/no_cakes_view.js.coffee
new file mode 100644
index 00000000..278d7d37
--- /dev/null
+++ b/app/assets/javascripts/backbone/views/cakes/no_cakes_view.js.coffee
@@ -0,0 +1,5 @@
+CakeSide.Views.Cakes ||= {}
+
+class CakeSide.Views.Cakes.NoCakesView extends Marionette.ItemView
+ template: JST["backbone/templates/cakes/no_cakes"]
+ tagName: 'li'
diff --git a/app/assets/javascripts/creations.js b/app/assets/javascripts/creations.js
deleted file mode 100644
index e91b76f1..00000000
--- a/app/assets/javascripts/creations.js
+++ /dev/null
@@ -1,4 +0,0 @@
-var Creations = Creations || {};
-Creations.Show = {
- initialize: function(){ }
-};
diff --git a/app/assets/javascripts/masonry.js.coffee b/app/assets/javascripts/masonry.js.coffee
index 539f3cb4..491769db 100644
--- a/app/assets/javascripts/masonry.js.coffee
+++ b/app/assets/javascripts/masonry.js.coffee
@@ -4,7 +4,6 @@ class window.Masonry
load: ->
$(@container).imagesLoaded =>
- console.log("load masonry.")
$(@container).masonry
itemSelector : '.span4'
isResizable: true
diff --git a/app/assets/javascripts/users_edit.js b/app/assets/javascripts/users_edit.js
deleted file mode 100644
index 493283c4..00000000
--- a/app/assets/javascripts/users_edit.js
+++ /dev/null
@@ -1,37 +0,0 @@
-var DeviseUsers = DeviseUsers || {};
-
-DeviseUsers.Edit = {
- initialize: function($){
- $('#edit_user').validate();
- $('#user_city').autocomplete({
- source: function(request, response){
- $.ajax({
- url: 'http://ws.geonames.org/searchJSON',
- dataType: "jsonp",
- data: {
- featureClass: "P",
- style: 'full',
- maxRows: 12,
- name_startsWith: request.term
- },
- success: function(data){
- response( $.map(data.geonames, function(item){
- return {
- label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
- value: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
- latitude: item.lat,
- longitude: item.lng
- }
- }));
- }
- });
- },
- minlength:2,
- select:function(event, ui){
- var item = ui.item;
- $('#user_latitude').val(item.latitude);
- $('#user_longitude').val(item.longitude);
- }
- });
- }
-};
diff --git a/app/assets/javascripts/utility/greeting.js.coffee b/app/assets/javascripts/utility/greeting.js.coffee
deleted file mode 100644
index cea58c7f..00000000
--- a/app/assets/javascripts/utility/greeting.js.coffee
+++ /dev/null
@@ -1,8 +0,0 @@
-class window.Greeting
- constructor:(@name) ->
-
- greet: () ->
- 'hi ' + @name
-
- goodbye: () ->
- 'goodbye ' + @name
diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss
index da34f861..8f19b2a4 100644
--- a/app/assets/stylesheets/application.css.scss
+++ b/app/assets/stylesheets/application.css.scss
@@ -8,7 +8,6 @@
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
- *= require jquery.fileupload-ui
*= require_self
*= require jquery.tagit
*= require jquery.ui.all
diff --git a/app/controllers/creations_controller.rb b/app/controllers/creations_controller.rb
index 34286188..02f7dcee 100644
--- a/app/controllers/creations_controller.rb
+++ b/app/controllers/creations_controller.rb
@@ -1,6 +1,4 @@
class CreationsController < ApplicationController
- before_filter :authenticate_user!, :except => [:show, :index]
-
def index
@creations = FindAllCreationsQuery.new.fetch(params)
expires_in(10.minutes) unless user_signed_in?
@@ -10,54 +8,4 @@ class CreationsController < ApplicationController
@creation = FindCreationQuery.new.fetch(params[:id])
expires_in(1.minute) unless user_signed_in?
end
-
- def new
- @creation = Creation.new
- @user = current_user
- end
-
- def edit
- @creation = current_user.creations.find(params[:id])
- end
-
- def create
- CreateCakeCommand.new(self).run(creation_params, params[:creation_tags])
- end
-
- def create_cake_succeeded(cake)
- @creation = cake
- redirect_to new_my_cake_photo_path(cake)
- end
-
- def create_cake_failed(cake)
- @creation = cake
- flash[:error] = @creation.errors.full_messages
- render :new
- end
-
- def update
- UpdateCakeCommand.new(self).run(params[:id], params[:creation_tags], creation_params)
- end
-
- def update_cake_succeeded(cake)
- @creation = cake
- redirect_to new_my_cake_photo_path(@creation)
- end
-
- def update_cake_failed(cake)
- @creation = cake
- flash[:error] = @creation.errors.full_messages
- render :edit
- end
-
- def destroy
- RemoveCakeCommand.new(self).run(params[:id])
- redirect_to my_dashboard_path
- end
-
- private
-
- def creation_params
- params.require(:creation).permit(:name, :story, :category_id)
- end
end
diff --git a/app/controllers/my/photos_controller.rb b/app/controllers/my/photos_controller.rb
deleted file mode 100644
index d67a17be..00000000
--- a/app/controllers/my/photos_controller.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-module My
- class PhotosController < BaseController
- before_filter :find_creation
-
- def initialize(mapper = PhotoToJQJsonMapper.new)
- @mapper = mapper
- super()
- end
-
- def index
- @photos = @cake.photos
- render json: { files: @photos.map { |photo| @mapper.map_from(photo) } }
- end
-
- def new
- @photo = Photo.new
- end
-
- def create
- render json: { files: [UploadPhoto.new.run(params[:cake_id], photo_params)] }
- end
-
- def destroy
- @photo = @cake.photos.find(params[:id])
- if @photo.destroy
- @cake.touch
- render json: { files: [@mapper.map_from(@photo)] }
- else
- render json: [ { error: "could not remove the photo" } ], status: 304
- end
- end
-
- private
-
- def find_creation
- @cake = current_user.creations.find(params[:cake_id])
- raise ActiveRecord::RecordNotFound unless @cake
- end
-
- def photo_params
- params.require(:photo).permit(:image)
- end
- end
-end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 72b4dc5c..464d05f9 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -1,7 +1,7 @@
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :creation
- has_many :activities, as: :subject
+ has_many :activities, as: :subject, dependent: :destroy
after_create :create_activity
private
diff --git a/app/services/application/photo_to_jq_json_mapper.rb b/app/services/application/photo_to_jq_json_mapper.rb
deleted file mode 100644
index f85235f4..00000000
--- a/app/services/application/photo_to_jq_json_mapper.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-class PhotoToJQJsonMapper
- def map_from(photo)
- {
- name: photo.image,
- url: photo.url_for(:large),
- thumbnail_url: photo.url_for(:thumb),
- delete_url: photo.id,
- delete_type: "DELETE"
- }
- end
-end
diff --git a/app/services/application/upload_photo.rb b/app/services/application/upload_photo.rb
index cba399c8..16b2c381 100644
--- a/app/services/application/upload_photo.rb
+++ b/app/services/application/upload_photo.rb
@@ -7,22 +7,11 @@ class UploadPhoto
def run(cake_id, params)
photo = @cakes.find(cake_id).photos.create!(image_processing: true, watermark: params[:watermark])
@message_bus.publish(:upload_photo, create_message_from(cake_id, params, photo))
- map_from(photo.id, params[:image].original_filename)
photo
end
private
- def map_from(photo_id, name)
- {
- name: name,
- url: "/_default.png",
- thumbnail_url: "/assets/thumb_default.png",
- delete_url: photo_id,
- delete_type: "DELETE"
- }
- end
-
def move_to_temporary_storage(temp_file_path, original_filename)
new_path = "#{create_tmp_dir}/#{original_filename}"
FileUtils.mv(temp_file_path, new_path)
diff --git a/app/views/creations/_form.html.erb b/app/views/creations/_form.html.erb
deleted file mode 100644
index 9e8f4a7b..00000000
--- a/app/views/creations/_form.html.erb
+++ /dev/null
@@ -1,53 +0,0 @@
-<% content_for :javascript do %>
- <script type="text/javascript" charset="utf-8">
- function loadTags() {
- var all_tags = [ <% ActsAsTaggableOn::Tag.pluck(:name).sort!.each { |item| %> '<%= item %>', <% } %> ];
- $('.tooltip-item').tooltip();
- $('#tags').tagit({ availableTags: all_tags });
- };
- $(document).ready(loadTags);
- </script>
-<% end %>
-<%= form_for(@creation, :html => {:multipart => true, :class => "form-horizontal"}) do |f| %>
- <fieldset>
- <div class="control-group">
- <%= f.label :name, :class => "control-label" %>
- <div class="controls">
- <%= f.text_field :name, :class => "input-xxlarge" %>
- </div>
- </div>
- <div class="control-group">
- <%= f.label :story, "Description", :class=> "control-label" %>
- <div class="controls">
- <%= f.text_area :story, :class =>"input-xxlarge", :rows => "3" %>
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">Category</label>
- <div class="controls">
- <%= select_tag 'creation[category_id]', options_from_collection_for_select(@categories, "id", "name") %>
- </div>
- </div>
- <div class="control-group">
- <label for="tags" class="control-label">Tags</label>
- <div class="controls">
- <% if @creation.present? %>
- <input name="creation_tags" type="text" id="tags" value="<% @creation.tags.map(&:name).each { |item| %><%= item %>,<% } %>" class="input-xxlarge" autocomplete="off" />
- <p class="help-block">
- <strong>Note:</strong> Adding tags will help people discover your creation.
- </p>
- <% else %>
- <input name="creation_tags" type="text" id="tags" value="" class="input-xxlarge" autocomplete="off" />
- <% end %>
- </div>
- </div>
- <div class="form-actions">
- <button type="submit" class="btn btn-primary">NEXT STEP</button>
- <% if @creation.new_record? %>
- <%= link_to "Cancel", my_cakes_path, class: 'btn' %>
- <% else %>
- <%= link_to "Cancel", creation_path(@creation), class: 'btn' %>
- <% end %>
- </div>
- </fieldset>
-<% end %>
diff --git a/app/views/creations/edit.html.erb b/app/views/creations/edit.html.erb
deleted file mode 100644
index a2d58a71..00000000
--- a/app/views/creations/edit.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-<% provide(:title, "Editing creation #{@creation.name}") %>
-<div class="row">
- <div class="span3">
- <div class="thumbnail">
- <%= avatar_for(current_user) %>
- <div class="caption">
- <h5><%= current_user.name %></h5>
- </div>
- </div>
- </div>
- <div class="span9">
- <h1><small>Edit</small> <%= @creation.name %> <small>(Step 1 of 2)</small></h1>
- <hr />
- <%= render 'form' %>
- </div>
-</div>
diff --git a/app/views/creations/index.html.erb b/app/views/creations/index.html.erb
index 0addba34..b38f687b 100644
--- a/app/views/creations/index.html.erb
+++ b/app/views/creations/index.html.erb
@@ -1,8 +1,7 @@
<% provide(:description, "CakeSide is a free site to share your cake creations and ideas with other cake fanatics like yourself") -%>
<% content_for :javascript do -%>
<script type="text/javascript">
- var ready = function(){ new Masonry('#creations-div').load(); };
- $(document).ready(ready);
+ $(function(){ new Masonry('#creations-div').load(); });
</script>
<% end -%>
<% unless user_signed_in? -%>
diff --git a/app/views/creations/new.html.erb b/app/views/creations/new.html.erb
deleted file mode 100644
index 538c82d0..00000000
--- a/app/views/creations/new.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<% provide(:title, "Share my creation") -%>
-<div class="row">
- <div class="span12">
- <h1>Share creation <small>(Step 1 of 2)</small></h1>
- <hr />
- <%= render 'form' %>
- </div>
-</div>
diff --git a/app/views/creations/show.html.erb b/app/views/creations/show.html.erb
index 70f88b85..0a25e63b 100644
--- a/app/views/creations/show.html.erb
+++ b/app/views/creations/show.html.erb
@@ -1,11 +1,5 @@
<% provide(:title, "#{@creation.name} By #{@creation.user.name}") -%>
<% provide(:description, "#{@creation.story}") -%>
-<% content_for :javascript do %>
-<script type="text/javascript">
- var ready = function(){ Creations.Show.initialize(); };
- $(document).ready(ready);
-</script>
-<% end -%>
<div class="row">
<div class="span6">
<img class="thumbnail" src="<%= @creation.primary_image.url_for(:large) %>" alt="<%= @creation.name %>" />
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
index 2f20bd3c..1cea802e 100644
--- a/app/views/layouts/_header.html.erb
+++ b/app/views/layouts/_header.html.erb
@@ -11,7 +11,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Creations<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
- <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_creation_path do %>
+ <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_user_session_path do %>
<i class="icon-edit icon-large"></i> Add Creation
<% end %>
</li>
@@ -69,7 +69,7 @@
</ul>
<ul class="nav pull-right">
<li>
- <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_creation_path do %>
+ <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_user_session_path do %>
<i class="icon-edit icon-large"></i> Add Creation
<% end %>
</li>
diff --git a/app/views/my/photos/_form.html.erb b/app/views/my/photos/_form.html.erb
deleted file mode 100644
index 01601017..00000000
--- a/app/views/my/photos/_form.html.erb
+++ /dev/null
@@ -1,89 +0,0 @@
-<% content_for :javascript do %>
-<script type="text/javascript" charset="utf-8">
- $(function () {
- $('#fileupload').fileupload({autoUpload:true, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i });
- $('#fileupload').fileupload( 'option', 'redirect', window.location.href.replace( /\/[^\/]*$/, '/cors/result.html?%s'));
- $('#fileupload').each(function () {
- var that = this;
- $.getJSON(this.action, function (result) {
- if (result) {
- $(that).fileupload('option', 'done').call(that, null, {result: result});
- }
- });
- });
- });
-</script>
-<% end %>
- <%= form_for [@cake, @photo], url: my_cake_photos_path, :html => { :multipart => true, :id => "fileupload" } do |f| %>
- <div class="row fileupload-buttonbar">
- <div class="span10">&nbsp;</div>
- <div class="span2">
- <span class="btn btn-success fileinput-button"><i class="icon-plus icon-white"></i><span> Browse... </span><%= f.file_field :image %></span>
- <%= link_to "NEXT", my_dashboard_path, :class => "btn btn-primary" %>
- </div>
- </div>
- <div class="fileupload-loading"></div>
- <br>
- <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
- <% end %>
-</div>
-
-<!-- The template to display files available for upload -->
-<script id="template-upload" type="text/x-tmpl">
-{% for (var i=0, file; file=o.files[i]; i++) { %}
- <tr class="template-upload fade">
- <td class="preview"><span class="fade"></span></td>
- <td class="name"><span>{%=file.name%}</span></td>
- <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
- {% if (file.error) { %}
- <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
- {% } else if (o.files.valid && !i) { %}
- <td>
- <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
- </td>
- <td class="start">{% if (!o.options.autoUpload) { %}
- <button class="btn btn-primary">
- <i class="icon-upload icon-white"></i>
- <span>Start</span>
- </button>
- {% } %}</td>
- {% } else { %}
- <td colspan="2"></td>
- {% } %}
- <td class="cancel">{% if (!i) { %}
- <button class="btn btn-warning">
- <i class="icon-ban-circle icon-white"></i>
- <span>Cancel</span>
- </button>
- {% } %}</td>
- </tr>
-{% } %}
-</script>
-<!-- The template to display files available for download -->
-<script id="template-download" type="text/x-tmpl">
-{% for (var i=0, file; file=o.files[i]; i++) { %}
- <tr class="template-download fade">
- {% if (file.error) { %}
- <td></td>
- <td class="name"><span>{%=file.name%}</span></td>
- <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
- <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
- {% } else { %}
- <td class="preview">{% if (file.thumbnail_url) { %}
- <img src="{%=file.thumbnail_url%}" style="width:260px;height:180px;">
- {% } %}</td>
- <td class="name">
- <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
- </td>
- <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
- <td colspan="2"></td>
- {% } %}
- <td class="delete">
- <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
- <i class="icon-trash icon-white"></i>
- <span>Remove</span>
- </button>
- </td>
- </tr>
-{% } %}
-</script>
diff --git a/app/views/my/photos/new.html.erb b/app/views/my/photos/new.html.erb
deleted file mode 100644
index 5ee789a4..00000000
--- a/app/views/my/photos/new.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<% provide(:title, "Upload images for this cake") -%>
-<div class="row">
- <div class="span12">
- <h1><small>Upload images of </small> <%= @cake.name %> <small> (Step 2 of 2)</small></h1>
- <hr>
- <%= render 'form' %>
- </div>
-</div>
diff --git a/app/views/my/settings/index.html.erb b/app/views/my/settings/index.html.erb
index 0d6bf464..4e6b1530 100644
--- a/app/views/my/settings/index.html.erb
+++ b/app/views/my/settings/index.html.erb
@@ -1,8 +1,9 @@
<% provide(:title, "My Settings") -%>
<% content_for :javascript do %>
<script type="text/javascript" charset="utf-8">
- var ready = function(){ DeviseUsers.Edit.initialize(jQuery); };
- $(document).ready(ready);
+ $(function(){
+ $('#edit_user').validate();
+ });
</script>
<% end %>
diff --git a/app/views/tutorials/index.html.erb b/app/views/tutorials/index.html.erb
index a981cc85..17794fa7 100644
--- a/app/views/tutorials/index.html.erb
+++ b/app/views/tutorials/index.html.erb
@@ -1,8 +1,7 @@
<% provide(:description, "The latest tutorials") -%>
<% content_for :javascript do -%>
<script type="text/javascript">
- var ready = function(){ new Masonry('#tutorials-div').load(); };
- $(document).ready(ready);
+ $(function(){ new Masonry('#tutorials-div').load(); });
</script>
<% end -%>
<div id="tutorials-div" class="row">
diff --git a/config/routes.rb b/config/routes.rb
index 47e30309..b7bfedd5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -13,12 +13,12 @@ Cake::Application.routes.draw do
get ':id/page/:page', :action => :show, :on => :collection
end
- resources :creations do
+ get '/creations/new', to: redirect('/login')
+ resources :creations, only: [:index, :show] do
resources :photos, only: [:index, :show]
resources :favorites, :only => [:index, :create]
get 'page/:page', :action => :index, :on => :collection
end
- resources :cakes
resources :profiles, :only => [:index, :show] do
get 'page/:page', :action => :index, :on => :collection
@@ -67,13 +67,11 @@ Cake::Application.routes.draw do
namespace :my do
get 'dashboard', to: 'dashboard#index'
- resources :cakes, only: [:index] do
- resources :photos, only: [:index, :new, :create, :destroy]
- end
+ resources :cakes, only: [:index]
resources :favorites, only: [:index]
resources :settings, only: [:index, :update]
resources :passwords, only: [:index, :update]
- resources :avatars, :only => [:edit, :update]
+ resources :avatars, only: [:edit, :update]
root to: "cakes#index"
end
end
diff --git a/spec/controllers/creations_controller_spec.rb b/spec/controllers/creations_controller_spec.rb
index b52cac83..5988ead4 100644
--- a/spec/controllers/creations_controller_spec.rb
+++ b/spec/controllers/creations_controller_spec.rb
@@ -17,110 +17,10 @@ describe CreationsController do
end
end
- context "when logged in" do
- before { http_login(user) }
-
- describe "#show" do
- it "assigns the requested creation" do
- get :show, :id => creation.id
- assigns(:creation).should == creation
- end
- end
-
- describe "#new" do
- it "assigns a new creation" do
- new_creation = double
- Creation.stub(:new).and_return(new_creation)
- get :new
- assigns(:creation).should be(new_creation)
- end
- end
-
- describe "#edit" do
- it "assigns the requested creation as @creation" do
- get :edit, :id => creation.id
- assigns(:creation).should eq(creation)
- end
- end
-
- describe "#post" do
- describe "with valid params" do
- let(:category) { create(:category) }
-
- before :each do
- post :create, creation: {
- name: 'stone',
- story: 'morning glory',
- category_id: category.id
- }, creation_tags: 'cake'
- end
-
- it "assigns a newly created creation" do
- assigns(:creation).should_not be_nil
- assigns(:creation).name.should == 'stone'
- assigns(:creation).story.should == 'morning glory'
- end
-
- it "redirects to the created creation" do
- response.should redirect_to(new_my_cake_photo_path(assigns(:creation)))
- end
- end
-
- describe "with invalid params" do
- before { post :create, :creation => {:name => '', category_id: Category.first.id} }
-
- it "re-renders the 'new' template" do
- response.should render_template("new")
- end
-
- it "should include the errors" do
- assigns(:creation).errors.count.should > 0
- end
- end
- end
-
- describe "#patch" do
- describe "with valid params" do
- before { patch :update, :id => creation.id, :creation => {:name => 'params'} }
-
- it "assigns the requested creation as @creation" do
- assigns(:creation).should == creation
- end
-
- it "redirects to the creation" do
- response.should redirect_to new_my_cake_photo_path(creation.reload)
- end
- end
-
- describe "with invalid params" do
- before { put :update, :id => creation.id, :creation => {:name=> nil } }
-
- it "assigns the creation as @creation" do
- assigns(:creation).should == creation
- end
-
- it "re-renders the 'edit' template" do
- response.should render_template("edit")
- end
-
- it "should display an error" do
- flash[:error].should_not be_nil
- end
- end
- end
-
- describe "#destroy" do
- before :each do
- delete :destroy, :id => creation.id
- end
-
- it "destroys the requested creation" do
- user.creations.count.should == 0
- end
-
- it "redirects to the creations list" do
- response.should redirect_to(my_dashboard_path)
- end
+ describe "#show" do
+ it "assigns the requested creation" do
+ get :show, :id => creation.id
+ assigns(:creation).should == creation
end
end
end
diff --git a/spec/controllers/my/photos_controller_spec.rb b/spec/controllers/my/photos_controller_spec.rb
deleted file mode 100644
index 401bca25..00000000
--- a/spec/controllers/my/photos_controller_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-require 'rails_helper'
-
-module My
- describe PhotosController do
- let(:user){ create(:user) }
- let(:cake){ create(:creation) }
-
- before(:each) do
- user.creations << cake
- http_login(user)
- end
-
- describe "#create" do
- let(:image) { Rack::Test::UploadedFile.new("spec/fixtures/images/gorilla.jpg", "image/jpeg") }
-
- before :each do
- xhr :post, :create, cake_id: cake.id, photo: { image: image }
- end
-
- it "returns http success" do
- response.should be_success
- end
-
- it "should upload a new photo" do
- json = JSON.parse(response.body)
- json["files"].first["name"].should_not be_nil
- json["files"].first["url"].should_not be_nil
- json["files"].first["thumbnail_url"].should_not be_nil
- json["files"].first["delete_url"].should_not be_nil
- json["files"].first["delete_type"].should == "DELETE"
- end
- end
-
- describe "#delete" do
- let!(:photo) { create(:photo, creation_id: cake.id, image_processing: nil) }
- let(:asset_host) { ENV['ASSET_HOST'] }
-
- before :each do
- delete :destroy, cake_id: cake.id, id: photo.id
- end
-
- it "returns http success" do
- response.should be_success
- end
-
- it "should destroy the photo" do
- Photo.exists?(photo.id).should be_falsey
- end
-
- it "should respond with the proper json" do
- response.body.should ==
- {
- files: [{
- name: "example.png",
- url: "#{asset_host}/uploads/photo/image/#{photo.id}/large_example.png",
- thumbnail_url: "#{asset_host}/uploads/photo/image/#{photo.id}/thumb_example.png",
- delete_url: photo.id,
- delete_type: "DELETE"
- }]
- }.to_json
- end
- end
- end
-end
diff --git a/spec/javascripts/backbone/models/cake_spec.js.coffee b/spec/javascripts/backbone/models/cake_spec.js.coffee
new file mode 100644
index 00000000..e69b3f6b
--- /dev/null
+++ b/spec/javascripts/backbone/models/cake_spec.js.coffee
@@ -0,0 +1,40 @@
+describe "CakeSide.Models.Cake", ->
+ createSUT = (attributes) ->
+ new CakeSide.Models.Cake(attributes)
+
+ describe "#validate", ->
+ it "returns an error when the name is null", ->
+ attributes =
+ name: null
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes, {})).not.toBe(null)
+ expect(cake.isValid()).toBeFalsy()
+
+ it "returns an error when the name is blank", ->
+ attributes =
+ name: ' '
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes, {})).not.toBe(null)
+ expect(cake.isValid()).toBeFalsy()
+
+
+ it 'returns an error when the category is blank', ->
+ attributes =
+ name: 'hi'
+ category_id: null
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes)).not.toBe(null)
+ expect(cake.isValid()).toBeFalsy()
+
+ it 'is valid when a name and category is specified', ->
+ attributes =
+ name: 'hi'
+ category_id: 1
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes)).toBeUndefined()
+ expect(cake.isValid()).toBeTruthy()
+
+ describe "#public_url", ->
+ it "returns the correct url", ->
+ result = createSUT(slug: '123-cake').public_url()
+ expect(result).toMatch(/^http:\/\/.+\/creations\/123-cake$/)
diff --git a/spec/javascripts/backbone/views/cake_view_spec.js.coffee b/spec/javascripts/backbone/views/cake_view_spec.js.coffee
new file mode 100644
index 00000000..c8480bc6
--- /dev/null
+++ b/spec/javascripts/backbone/views/cake_view_spec.js.coffee
@@ -0,0 +1,15 @@
+describe "CakeSide.Views.Cakes.CakeView", ->
+ cake = new CakeSide.Models.Cake
+ name: 'chocolate'
+ view = new CakeSide.Views.Cakes.CakeView
+ model: cake
+
+ describe "when there are no photos", ->
+ beforeEach ->
+ view.render()
+
+ it 'renders the cake', ->
+ expect(view.$el.html()).toMatch(/chocolate/)
+
+ it 'does not display any photos', ->
+ expect(view.$el.html()).not.toMatch(/img/)
diff --git a/spec/javascripts/utility/greeting_spec.js b/spec/javascripts/utility/greeting_spec.js
deleted file mode 100644
index dc1e5bf8..00000000
--- a/spec/javascripts/utility/greeting_spec.js
+++ /dev/null
@@ -1,16 +0,0 @@
-describe ("Greeting", function() {
- beforeEach (function() {
- sut = new Greeting('mo');
- });
- var sut;
- describe ("when greeting someone", function() {
- it ("should say their name", function() {
- expect(sut.greet()).toEqual('hi mo');
- });
- });
- describe ("when saying goodbye", function() {
- it ("should say their name", function() {
- expect(sut.goodbye()).toEqual('goodbye mo');
- });
- });
-});
diff --git a/spec/routing/creations_routing_spec.rb b/spec/routing/creations_routing_spec.rb
index 91dea3c2..adac466d 100644
--- a/spec/routing/creations_routing_spec.rb
+++ b/spec/routing/creations_routing_spec.rb
@@ -10,29 +10,8 @@ describe CreationsController do
{ :get => "/creations" }.should route_to(:controller => "creations", :action => "index")
end
- it "recognizes and generates #new" do
- { :get => "/creations/new" }.should route_to(:controller => "creations", :action => "new")
- end
-
it "recognizes and generates #show" do
{ :get => "/creations/1" }.should route_to(:controller => "creations", :action => "show", :id => "1")
end
-
- it "recognizes and generates #edit" do
- { :get => "/creations/1/edit" }.should route_to(:controller => "creations", :action => "edit", :id => "1")
- end
-
- it "recognizes and generates #create" do
- { :post => "/creations" }.should route_to(:controller => "creations", :action => "create")
- end
-
- it "recognizes and generates #update" do
- { :put => "/creations/1" }.should route_to(:controller => "creations", :action => "update", :id => "1")
- end
-
- it "recognizes and generates #destroy" do
- { :delete => "/creations/1" }.should route_to(:controller => "creations", :action => "destroy", :id => "1")
- end
-
end
end