Finish review for depluralization and related updates
Kennedy Clark [Tue, 26 May 2009 02:45:27 +0000 (02:45 +0000)]
lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod
lib/Catalyst/Manual/Tutorial/05_Authentication.pod
lib/Catalyst/Manual/Tutorial/06_Authorization.pod
lib/Catalyst/Manual/Tutorial/08_Testing.pod

index 3e7e02e..e63500d 100644 (file)
@@ -1066,9 +1066,9 @@ time entered for it (see the last line in the listing below):
 Notice in the debug log that the SQL DBIC generated has changed to
 incorporate the datetime logic:
 
-    INSERT INTO book ( created, rating, title, updated) VALUES ( ?, ?, ?, ? ): 
+    INSERT INTO book ( created, rating, title, updated ) VALUES ( ?, ?, ?, ? ): 
     '2009-05-25 20:39:41', '5', 'TCPIP_Illustrated_Vol-2', '2009-05-25 20:39:41'
-    INSERT INTO book_author ( author_id, book_id) VALUES ( ?, ? ): '4', '10'
+    INSERT INTO book_author ( author_id, book_id ) VALUES ( ?, ? ): '4', '10'
 
 
 =head2 Create a ResultSet Class
index 6c41ec7..40fd38f 100644 (file)
@@ -159,7 +159,7 @@ C<lib/MyApp/Schema/Result/User.pm>:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *foreign* table (aka, foreign key in peer table)
-    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRole', 'user_id');
+    __PACKAGE__->has_many(map_user_roles => 'MyApp::Schema::Result::UserRole', 'user_id');
     
     # many_to_many():
     #   args:
@@ -167,7 +167,7 @@ C<lib/MyApp/Schema/Result/User.pm>:
     #     2) Name of has_many() relationship this many_to_many() is shortcut for
     #     3) Name of belongs_to() relationship in model class of has_many() above
     #   You must already have the has_many() defined to use a many_to_many().
-    __PACKAGE__->many_to_many(roles => 'map_user_role', 'role');
+    __PACKAGE__->many_to_many(roles => 'map_user_roles', 'role');
 
 
 C<lib/MyApp/Schema/Result/Role.pm>:
@@ -181,7 +181,7 @@ C<lib/MyApp/Schema/Result/Role.pm>:
     #     1) Name of relationship, DBIC will create accessor with this name
     #     2) Name of the model class referenced by this relationship
     #     3) Column name in *foreign* table (aka, foreign key in peer table)
-    __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRole', 'role_id');
+    __PACKAGE__->has_many(map_user_roles => 'MyApp::Schema::Result::UserRole', 'role_id');
 
 
 C<lib/MyApp/Schema/Result/UserRole.pm>:
@@ -253,7 +253,8 @@ Edit C<lib/MyApp.pm> and update it as follows (everything below
 C<StackTrace> is new):
 
     # Load plugins
-    use Catalyst qw/-Debug
+    use Catalyst qw/
+                    -Debug
                     ConfigLoader
                     Static::Simple
     
@@ -745,12 +746,20 @@ password stored for this user.
 
 Then run the following command:
 
-    $ perl -Ilib set_hashed_passwords.pl
+    $ DBIC_TRACE=1 perl -Ilib set_hashed_passwords.pl
 
 We had to use the C<-Ilib> arguement to tell perl to look under the 
 C<lib> directory for our C<MyApp::Schema> model.
 
-Then dump the users table to verify that it worked:
+The DBIC_TRACE output should show that the update worked:
+
+    $ DBIC_TRACE=1 perl -Ilib set_hashed_passwords.pl
+    SELECT me.id, me.username, me.password, me.email_address, me.first_name, me.last_name, me.active FROM user me: 
+    UPDATE user SET password = ? WHERE ( id = ? ): 'oXiyAcGOjowz7ISUhpIm1IrS8AxSZ9r4jNjpX9VnVeQmN6GRtRKTz', '1'
+    UPDATE user SET password = ? WHERE ( id = ? ): 'PmyEPrkB8EGwvaF/DvJm7LIfxoZARjv8ygFIR7pc1gEA1OfwHGNzs', '2'
+    UPDATE user SET password = ? WHERE ( id = ? ): 'h7CS1Fm9UCs4hjcbu2im0HumaHCJUq4Uriac+SQgdUMUfFSoOrz3c', '3'
+
+But we can further confirm our actions by dumping the users table:
 
     $ sqlite3 myapp.db "select * from user"
     1|test01|38d3974fa9e9263099f7bc2574284b2f55473a9bM=fwpX2NR8|t01@na.com|Joe|Blow|1
index cda2f7b..61248a4 100644 (file)
@@ -79,7 +79,8 @@ Catalyst.
 Edit C<lib/MyApp.pm> and add C<Authorization::Roles> to the list:
 
     # Load plugins
-    use Catalyst qw/-Debug
+    use Catalyst qw/
+                    -Debug
                     ConfigLoader
                     Static::Simple
                 
@@ -107,6 +108,7 @@ like this:
         'Catalyst::Plugin::Authorization::Roles' => '0',
     );
 
+
 =head2 Add Role-Specific Logic to the "Book List" Template
 
 Open C<root/src/books/list.tt2> in your editor and add the following
@@ -117,7 +119,7 @@ lines to the bottom of the file:
     
     <ul>
       [% # Dump list of roles -%]
-      [% FOR role = c.user.role %]<li>[% role %]</li>[% END %]
+      [% FOR role = c.user.roles %]<li>[% role %]</li>[% END %]
     </ul>
     
     <p>
@@ -175,9 +177,9 @@ updating C<url_create> to match the following code:
     
             # Add a record to the join table for this book, mapping to
             # appropriate author
-            $book->add_to_book_author({author_id => $author_id});
+            $book->add_to_book_authors({author_id => $author_id});
             # Note: Above is a shortcut for this:
-            # $book->create_related('book_author', {author_id => $author_id});
+            # $book->create_related('book_authors', {author_id => $author_id});
     
             # Assign the Book object to the stash for display in the view
             $c->stash->{book} = $book;
@@ -305,7 +307,7 @@ match the following code:
     
         # Redirect the user back to the list page
         $c->response->redirect($c->uri_for($self->action_for('list')));
-    }    
+    }
 
 Here, we C<detach> to an error page if the user is lacking the 
 appropriate permissions.  For this to work, we need to make 
index c8671c0..71045a6 100644 (file)
@@ -237,7 +237,12 @@ editor and enter the following:
     # Log in as each user
     # Specify username and password on the URL
     $ua1->get_ok("http://localhost/login?username=test01&password=mypass", "Login 'test01'");
-    $ua1->get_ok("http://localhost/login?username=test02&password=mypass", "Login 'test02'");
+    # Could make user2 like user1 above, but use the form to show another way
+    $ua2->submit_form(
+        fields => {
+            username => 'test02',
+            password => 'mypass',
+        });
     
     # Go back to the login page and it should show that we are already logged in
     $_->get_ok("http://localhost/login", "Return to '/login'") for $ua1, $ua2;