Permalink
Browse files

Chapter 10 complete

  • Loading branch information...
1 parent 44994c5 commit 9f3f55a2ac4356d9ecc4885471d5569f7f2f1a2b @stefanklumpp committed Apr 9, 2012
View
@@ -22,28 +22,10 @@
</component>
<component name="FileEditorManager">
<leaf>
- <file leaf-file-name="home.html.erb" pinned="false" current="true" current-in-tab="true">
+ <file leaf-file-name="home.html.erb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/views/static_pages/home.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- </file>
- <file leaf-file-name="microposts_controller.rb" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/app/controllers/microposts_controller.rb">
- <provider selected="true" editor-type-id="text-editor">
- <state line="12" column="5" selection-start="365" selection-end="365" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- </file>
- <file leaf-file-name="user.rb" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/app/models/user.rb">
- <provider selected="true" editor-type-id="text-editor">
- <state line="30" column="5" selection-start="1043" selection-end="1043" vertical-scroll-proportion="0.0">
+ <state line="30" column="127" selection-start="873" selection-end="873" vertical-scroll-proportion="-19.2">
<folding />
</state>
</provider>
@@ -52,7 +34,7 @@
<file leaf-file-name="_micropost_form.html.erb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/views/shared/_micropost_form.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="13" selection-start="13" selection-end="13" vertical-scroll-proportion="-0.0">
+ <state line="0" column="13" selection-start="13" selection-end="13" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -97,7 +79,25 @@
<file leaf-file-name="_feed_item.html.erb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/views/shared/_feed_item.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="9" column="5" selection-start="340" selection-end="340" vertical-scroll-proportion="0.0">
+ <state line="14" column="5" selection-start="532" selection-end="532" vertical-scroll-proportion="-8.96">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file leaf-file-name="micropost_pages_spec.rb" pinned="false" current="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/spec/requests/micropost_pages_spec.rb">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="44" column="2" selection-start="1082" selection-end="1082" vertical-scroll-proportion="0.0">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file leaf-file-name="microposts_controller.rb" pinned="false" current="true" current-in-tab="true">
+ <entry file="file://$PROJECT_DIR$/app/controllers/microposts_controller.rb">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="26" column="5" selection-start="619" selection-end="619" vertical-scroll-proportion="0.49582836">
<folding />
</state>
</provider>
@@ -106,7 +106,7 @@
<file leaf-file-name="_micropost.html.erb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/views/microposts/_micropost.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="-0.0">
+ <state line="10" column="5" selection-start="348" selection-end="348" vertical-scroll-proportion="-6.4">
<folding />
</state>
</provider>
@@ -122,22 +122,22 @@
<component name="IdeDocumentHistory">
<option name="changedFiles">
<list>
- <option value="$PROJECT_DIR$/config/routes.rb" />
<option value="$PROJECT_DIR$/app/views/users/new.html.erb" />
<option value="$PROJECT_DIR$/app/views/users/edit.html.erb" />
<option value="$PROJECT_DIR$/app/views/shared/_error_messages.html.erb" />
<option value="$PROJECT_DIR$/spec/requests/user_pages_spec.rb" />
- <option value="$PROJECT_DIR$/spec/requests/micropost_pages_spec.rb" />
<option value="$PROJECT_DIR$/lib/tasks/sample_data.rake" />
<option value="$PROJECT_DIR$/app/views/shared/_micropost_form.html.erb" />
<option value="$PROJECT_DIR$/spec/models/user_spec.rb" />
<option value="$PROJECT_DIR$/spec/requests/static_pages_spec.rb" />
<option value="$PROJECT_DIR$/app/controllers/static_pages_controller.rb" />
<option value="$PROJECT_DIR$/app/views/shared/_feed.html.erb" />
- <option value="$PROJECT_DIR$/app/views/shared/_feed_item.html.erb" />
- <option value="$PROJECT_DIR$/app/controllers/microposts_controller.rb" />
<option value="$PROJECT_DIR$/app/models/user.rb" />
<option value="$PROJECT_DIR$/app/views/static_pages/home.html.erb" />
+ <option value="$PROJECT_DIR$/app/views/microposts/_micropost.html.erb" />
+ <option value="$PROJECT_DIR$/app/views/shared/_feed_item.html.erb" />
+ <option value="$PROJECT_DIR$/spec/requests/micropost_pages_spec.rb" />
+ <option value="$PROJECT_DIR$/app/controllers/microposts_controller.rb" />
</list>
</option>
</component>
@@ -172,12 +172,12 @@
<sortByType />
</navigator>
<panes>
- <pane id="Scope">
- <subPane subId="Project Files">
+ <pane id="RailsProjectView">
+ <subPane>
<PATH>
- <PATH_ELEMENT USER_OBJECT="Root">
- <option name="myItemId" value="" />
- <option name="myItemType" value="" />
+ <PATH_ELEMENT>
+ <option name="myItemId" value="sample_app" />
+ <option name="myItemType" value="org.jetbrains.plugins.ruby.rails.projectView.v2.nodes.RailsProjectNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
@@ -602,12 +602,12 @@
</PATH>
</subPane>
</pane>
- <pane id="RailsProjectView">
- <subPane>
+ <pane id="Scope">
+ <subPane subId="Project Files">
<PATH>
- <PATH_ELEMENT>
- <option name="myItemId" value="sample_app" />
- <option name="myItemType" value="org.jetbrains.plugins.ruby.rails.projectView.v2.nodes.RailsProjectNode" />
+ <PATH_ELEMENT USER_OBJECT="Root">
+ <option name="myItemId" value="" />
+ <option name="myItemType" value="" />
</PATH_ELEMENT>
</PATH>
</subPane>
@@ -885,12 +885,11 @@
<frame x="0" y="22" width="1680" height="983" extended-state="0" />
<editor active="true" />
<layout>
- <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32995495" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Data Sources" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
- <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.19485295" sideWeight="0.670045" order="0" side_tool="false" content_ui="combo" />
+ <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.19730392" sideWeight="0.670045" order="0" side_tool="false" content_ui="combo" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
@@ -900,6 +899,7 @@
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32995495" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+ <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32995495" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
@@ -979,13 +979,6 @@
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/spec/requests/micropost_pages_spec.rb">
- <provider selected="true" editor-type-id="text-editor">
- <state line="18" column="36" selection-start="420" selection-end="420" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
<entry file="file://$PROJECT_DIR$/spec/factories.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="18" column="85" selection-start="326" selection-end="326" vertical-scroll-proportion="0.0">
@@ -1000,9 +993,9 @@
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/app/views/microposts/_micropost.html.erb">
+ <entry file="file://$PROJECT_DIR$/app/models/user.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
+ <state line="30" column="5" selection-start="1043" selection-end="1043" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -1021,6 +1014,13 @@
</state>
</provider>
</entry>
+ <entry file="file://$PROJECT_DIR$/spec/requests/static_pages_spec.rb">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="24" column="46" selection-start="747" selection-end="747" vertical-scroll-proportion="0.0">
+ <folding />
+ </state>
+ </provider>
+ </entry>
<entry file="file://$PROJECT_DIR$/app/controllers/static_pages_controller.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="5" selection-start="212" selection-end="212" vertical-scroll-proportion="0.0">
@@ -1030,42 +1030,40 @@
</entry>
<entry file="file://$PROJECT_DIR$/app/views/shared/_feed.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="5" column="9" selection-start="183" selection-end="183" vertical-scroll-proportion="0.0">
- <folding />
- </state>
+ <state line="5" column="9" selection-start="183" selection-end="183" vertical-scroll-proportion="0.0" />
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/app/views/shared/_feed_item.html.erb">
+ <entry file="file://$PROJECT_DIR$/app/views/static_pages/home.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="9" column="5" selection-start="340" selection-end="340" vertical-scroll-proportion="0.0">
+ <state line="30" column="127" selection-start="873" selection-end="873" vertical-scroll-proportion="-19.2">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/app/models/user.rb">
+ <entry file="file://$PROJECT_DIR$/app/views/microposts/_micropost.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="30" column="5" selection-start="1043" selection-end="1043" vertical-scroll-proportion="0.0">
+ <state line="10" column="5" selection-start="348" selection-end="348" vertical-scroll-proportion="-6.4">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/app/controllers/microposts_controller.rb">
+ <entry file="file://$PROJECT_DIR$/app/views/shared/_feed_item.html.erb">
<provider selected="true" editor-type-id="text-editor">
- <state line="12" column="5" selection-start="365" selection-end="365" vertical-scroll-proportion="0.0">
+ <state line="14" column="5" selection-start="532" selection-end="532" vertical-scroll-proportion="-8.96">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/spec/requests/static_pages_spec.rb">
+ <entry file="file://$PROJECT_DIR$/spec/requests/micropost_pages_spec.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="24" column="46" selection-start="747" selection-end="747" vertical-scroll-proportion="0.0">
+ <state line="44" column="2" selection-start="1082" selection-end="1082" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/app/views/static_pages/home.html.erb">
+ <entry file="file://$PROJECT_DIR$/app/controllers/microposts_controller.rb">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
+ <state line="26" column="5" selection-start="619" selection-end="619" vertical-scroll-proportion="0.49582836">
<folding />
</state>
</provider>
@@ -1,5 +1,6 @@
class MicropostsController < ApplicationController
before_filter :signed_in_user, only: [:create, :destroy]
+ before_filter :correct_user, only: :destroy
def create
@micropost = current_user.microposts.build(params[:micropost])
@@ -13,5 +14,16 @@ def create
end
def destroy
+ @micropost.destroy
+ redirect_back_or root_path
end
+
+ private
+
+ def correct_user
+ @micropost = current_user.microposts.find(params[:id])
+ rescue
+ redirect_to root_path
+ end
+
end
@@ -3,4 +3,9 @@
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
+ <% if current_user?(micropost.user) %>
+ <%= link_to "delete", micropost, method: :delete,
+ confirm: "You sure?",
+ title: micropost.content %>
+ <% end %>
</li>
@@ -1,10 +1,15 @@
<li id="<%= feed_item.id %>">
<%= link_to gravatar_for(feed_item.user), feed_item.user %>
<span class="user">
- <%= link_to feed_item.user.name, feed_item.user %>
- </span>
+ <%= link_to feed_item.user.name, feed_item.user %>
+ </span>
<span class="content"><%= feed_item.content %></span>
- <span class="timestamp">
- Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
- </span>
+ <span class="timestamp">
+ Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
+ </span>
+ <% if current_user?(feed_item.user) %>
+ <%= link_to "delete", feed_item, method: :delete,
+ confirm: "You sure?",
+ title: feed_item.content %>
+ <% end %>
</li>
@@ -30,4 +30,17 @@
end
end
end
+
+ describe "micropost destruction" do
+ before { FactoryGirl.create(:micropost, user: user) }
+
+ describe "as correct user" do
+ before { visit root_path }
+
+ it "should delete a micropost" do
+ expect { click_link "delete" }.should change(Micropost, :count).by(-1)
+ end
+ end
+ end
+
end

0 comments on commit 9f3f55a

Please sign in to comment.