Commit 82568208

mo khan <mo@mokhan.ca>
2014-07-05 23:03:12
remove is_restricted.
1 parent e6d58e3
app/assets/javascripts/backbone/models/cake.js.coffee
@@ -8,7 +8,6 @@ class CakeSide.Models.Cake extends Backbone.Model
     story: null
     created_at: null
     updated_at: null
-    is_restricted: false
     category_id: null
 
   validate: (attributes, options) ->
app/assets/javascripts/backbone/templates/cakes/edit.jst.ejs
@@ -48,14 +48,6 @@
           <input name="cake_tags" type="text" id="cake_tags" value="<%= tags %>" class="input-xxlarge" autocomplete="off" />
           </div>
         </div>
-        <div class="control-group">
-          <div class="controls">
-            <label class="checkbox">
-              <input class="input-xxlarge" id="cake_is_restricted" type="checkbox" <%= cake.is_restricted ? "checked=checked" : "" %> />
-              This cake is for adults only.
-            </label>
-          </div>
-        </div>
         <div class="form-actions">
           <button id='save-button' type="submit" class="btn btn-primary">Publish</button>
           <a href="#cakes/<%= cake.id %>" class="btn">Cancel</a>
app/assets/javascripts/backbone/views/cakes/edit_view.js.coffee
@@ -11,7 +11,6 @@ class CakeSide.Views.Cakes.EditView extends Marionette.CompositeView
     description: "#cake_story"
     category: "#cake_category_id"
     tags: "#cake_tags"
-    is_restricted: "#cake_is_restricted"
     save_button: '#save-button'
 
   modelEvents:
@@ -58,7 +57,6 @@ class CakeSide.Views.Cakes.EditView extends Marionette.CompositeView
     @model.set('story', @ui.description.val())
     @model.set('category_id', @ui.category.val())
     @model.set('tags', @ui.tags.val())
-    @model.set('is_restricted', @ui.is_restricted.attr('checked') == "checked")
     @model.isValid()
 
   displayError: (model, error) ->
app/controllers/api/v1/cakes_controller.rb
@@ -44,7 +44,7 @@ module Api
       private
 
       def cake_params
-        params.require(:cake).permit(:name, :story, :is_restricted, :watermark, :category_id, :tags)
+        params.require(:cake).permit(:name, :story, :watermark, :category_id, :tags)
       end
     end
   end
app/controllers/creations_controller.rb
@@ -58,6 +58,6 @@ class CreationsController < ApplicationController
   private
 
   def creation_params
-    params.require(:creation).permit(:name, :story, :is_restricted, :watermark, :category_id)
+    params.require(:creation).permit(:name, :story, :watermark, :category_id)
   end
 end
app/models/creation.rb
@@ -23,10 +23,6 @@ class Creation < ActiveRecord::Base
     photos.count > 0
   end
 
-  def is_safe_for_children?
-    is_restricted == false
-  end
-
   def is_liked_by(user)
     favorites.where(user: user).any?
   end
@@ -34,8 +30,4 @@ class Creation < ActiveRecord::Base
   def liked_by(user)
     favorites.find_or_create_by(user: user)
   end
-
-  def hide_from_children!
-    update_attribute(:is_restricted, true)
-  end
 end
app/models/creation_repository.rb
@@ -11,7 +11,7 @@ class CreationRepository
   end
 
   def visible_creations
-    connection.distinct.includes(:user, :photos).joins(:photos).where(is_restricted: false, 'photos.image_processing' => nil)
+    connection.distinct.includes(:user, :photos).joins(:photos).where('photos.image_processing' => nil)
   end
 
   private
app/services/application/handlers/publish_cake_to_twitter.rb
@@ -15,7 +15,7 @@ class PublishCakeToTwitter
   private
 
   def tweet_about(cake)
-    @twitter.tweet(tweet_for(cake)) if cake.is_safe_for_children? && cake.published?
+    @twitter.tweet(tweet_for(cake)) if cake.published?
   end
 
   def tweet_for(cake)
app/services/application/create_cake_command.rb
@@ -7,7 +7,6 @@ class CreateCakeCommand
 
   def run(attributes, tags)
     cake = @current_user.create_cake(name: attributes[:name], description: attributes[:story], category: Category.find(attributes[:category_id]), watermark: attributes[:watermark])
-    cake.hide_from_children! if attributes[:is_restricted].present? && attributes[:is_restricted] == true
     @current_user.tag(cake, with: tags, on: :tags)
 
     if cake.save
app/views/api/v1/cakes/_cake.json.jbuilder
@@ -3,7 +3,6 @@ json.name cake.name
 json.slug cake.to_param
 json.story cake.story
 json.watermark cake.watermark
-json.is_restricted cake.is_restricted
 json.category do
   json.id cake.category.id
   json.name cake.category.name
app/views/creations/_form.html.erb
@@ -47,14 +47,6 @@
         <input name="creation_tags" type="text" id="tags" value="" class="input-xxlarge" autocomplete="off" />
       <% end %>
     </div>
-    </div>
-        <div class="control-group">
-      <div class="controls">
-        <label class="checkbox">
-          <%= f.check_box :is_restricted, :class =>"input-xxlarge" %>
-          This cake is for adults only.
-        </label>
-      </div>
     </div>
     <div class="form-actions">
       <button type="submit" class="btn btn-primary">NEXT STEP</button>
db/migrate/20140705225150_drop_is_restricted_from_creations.rb
@@ -0,0 +1,5 @@
+class DropIsRestrictedFromCreations < ActiveRecord::Migration
+  def change
+    remove_column :creations, :is_restricted
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140607232108) do
+ActiveRecord::Schema.define(version: 20140705225150) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -65,7 +65,6 @@ ActiveRecord::Schema.define(version: 20140607232108) do
     t.datetime "updated_at"
     t.integer  "user_id"
     t.string   "image"
-    t.boolean  "is_restricted",   default: false, null: false
     t.string   "watermark"
     t.integer  "photos_count",    default: 0
     t.integer  "favorites_count", default: 0
spec/controllers/creations_controller_spec.rb
@@ -10,17 +10,11 @@ describe CreationsController do
   end
 
   describe "#index" do
-    let(:restricted_creation){ create(:creation, :user => user, :is_restricted => true) }
-
     before { get :index }
 
     it "should display all creations" do
       assigns(:creations).should include(creation)
     end
-
-    it "should not include restricted creations" do
-      assigns(:creations).should_not include(restricted_creation)
-    end
   end
 
   context "when logged in" do
@@ -57,7 +51,6 @@ describe CreationsController do
           post :create, creation: {
             name: 'stone',
             story: 'morning glory',
-            is_restricted: true,
             watermark: "watery",
             category_id: category.id
           }, creation_tags: 'cake'
@@ -67,7 +60,6 @@ describe CreationsController do
           assigns(:creation).should_not be_nil
           assigns(:creation).name.should == 'stone'
           assigns(:creation).story.should == 'morning glory'
-          assigns(:creation).is_restricted.should be_truthy
           assigns(:creation).watermark.should == 'watery'
         end
 
spec/features/upload_creation_spec.rb
@@ -16,10 +16,7 @@ describe "uploading a new creation", :js => true do
     wait_for_ajax
     within(".form-horizontal") do
       fill_in("cake_name", with: "yummy cake")
-      fill_in("cake_watermark", with: "yummy")
-      fill_in("cake_story", with: "this was just so damn yummy so i ate it alone.")
       select(category_2.name, from: 'cake_category_id')
-      #fill_in("cake_tags", :with => "cake, yummy")
     end
     click_button("Create")
   end
spec/models/creation_repository_spec.rb
@@ -4,7 +4,6 @@ describe CreationRepository do
   describe "#visible_creations" do
     let!(:user){ create(:user) }
     let!(:published_cake){ create(:creation, user: user) }
-    let!(:restricted_cake){ create(:creation, user: user, is_restricted: true) }
 
     before :each do
       published_cake.photos.create(image: 'example.png', image_processing: nil)
@@ -12,10 +11,6 @@ describe CreationRepository do
 
     let(:results) { subject.visible_creations }
 
-    it "returns cakes that are not restricted" do
-      expect(results).to_not include(restricted_cake)
-    end
-
     it "returns cakes that do not have photos that are processing" do
       expect(results.count).to eql(1)
       expect(results).to include(published_cake)
spec/services/handlers/publish_cake_to_twitter_spec.rb
@@ -24,7 +24,6 @@ describe PublishCakeToTwitter do
 
     context "when the cake is published and safe for kids" do
       before :each do
-        cake.stub(:is_safe_for_children?).and_return(true)
         cake.stub(:published?).and_return(true)
       end
 
@@ -36,7 +35,6 @@ describe PublishCakeToTwitter do
 
     context "when the cake is not published" do
       before :each do
-        cake.stub(:is_safe_for_children?).and_return(true)
         cake.stub(:published?).and_return(false)
       end
 
@@ -45,17 +43,5 @@ describe PublishCakeToTwitter do
         twitter.should_not have_received(:tweet)
       end
     end
-
-    context "when the cake is not safe for children" do
-      before :each do
-        cake.stub(:is_safe_for_children?).and_return(false)
-        cake.stub(:published?).and_return(true)
-      end
-
-      it "should not publish any tweets" do
-        subject.handle(cake_id: id)
-        twitter.should_not have_received(:tweet)
-      end
-    end
   end
 end
spec/services/queries/find_all_creations_query_spec.rb
@@ -6,7 +6,6 @@ describe FindAllCreationsQuery do
 
   let!(:cake_with_a_photo) { create(:creation) }
   let!(:cake_without_a_photo) { create(:creation, photos: []) }
-  let!(:restricted_cake) { create(:creation, is_restricted: true, photos: [create(:photo)]) }
 
   before :each do
     cake_with_a_photo.photos << create(:photo)
@@ -20,8 +19,4 @@ describe FindAllCreationsQuery do
   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