<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ganesh Kathare&#039;s Blog</title>
	<atom:link href="http://ganeshkathare.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ganeshkathare.wordpress.com</link>
	<description>Jruby, Ruby, Rails Developer</description>
	<lastBuildDate>Fri, 07 Oct 2011 12:19:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ganeshkathare.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ganesh Kathare&#039;s Blog</title>
		<link>http://ganeshkathare.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ganeshkathare.wordpress.com/osd.xml" title="Ganesh Kathare&#039;s Blog" />
	<atom:link rel='hub' href='http://ganeshkathare.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Rails &#8211; set restriction and permission on attributes at model level based on role system (using restricted_attributes plugin / gem)</title>
		<link>http://ganeshkathare.wordpress.com/2011/08/30/rails-set-restriction-and-permission-on-attributes-at-model-level-based-on-role-system-using-restricted_attributes-plugin-gem/</link>
		<comments>http://ganeshkathare.wordpress.com/2011/08/30/rails-set-restriction-and-permission-on-attributes-at-model-level-based-on-role-system-using-restricted_attributes-plugin-gem/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 20:08:16 +0000</pubDate>
		<dc:creator>Ganesh Kathare</dc:creator>
				<category><![CDATA[Jruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[rails 3]]></category>
		<category><![CDATA[rails params validator]]></category>
		<category><![CDATA[rails restricted attributes]]></category>
		<category><![CDATA[rails restricted_attributes gem]]></category>
		<category><![CDATA[rails restricted_attributes plugin]]></category>
		<category><![CDATA[restrict attribute at model level]]></category>
		<category><![CDATA[restricted_attributes]]></category>
		<category><![CDATA[set restriction and permission]]></category>
		<category><![CDATA[validate params rails]]></category>

		<guid isPermaLink="false">http://ganeshkathare.wordpress.com/?p=70</guid>
		<description><![CDATA[Rails &#8211; set restriction and permission on attributes at model level based on role system (using restricted_attributes plugin / gem) &#8211; validate params at model level RestrictedAttributes  Plugin / Gem: This restricted_attributes plugin provides the capabilities to restrict attributes (fields) of db table&#8217;s while add or update a record. It validates your attributes values before [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=70&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#000000;"><strong>Rails &#8211; set restriction and permission on attributes at model level based on role system (using restricted_attributes plugin / gem) &#8211; validate params at model level</strong></span></p>
<p><span style="color:#808000;"><strong>RestrictedAttributes  Plugin / Gem:</strong></span></p>
<p>This <strong>restricted_attributes</strong> plugin provides the capabilities to restrict attributes (fields) of db table&#8217;s while add or update a record. It validates your attributes values before your validation stuff.</p>
<p><span style="color:#808000;"><strong>Features :</strong></span></p>
<ul>
<li>Provides four different ways of restriction on fields (i.e read_only, create_only, update_only and hidden)</li>
<li>Restrict to add/modify values of particular attributes at model level while creating/updating a record.</li>
<li>Restrict functionality perform at before validation.</li>
<li>Able to set restriction on instance variables also.</li>
<li>OPTIONAL: It can also works on the basis of declarative authorization roles system.</li>
<li>So, able to set role wise restriction/permission on various users to change the value of an attributes.</li>
</ul>
<p><span style="color:#808000;"><strong>More Information and download links :</strong></span></p>
<p>Plugin :-  <a href="https://github.com/gkathare/restricted_attributes">https://github.com/gkathare/restricted_attributes</a></p>
<p>Gem    :- <a href="http://rubygems.org/gems/restricted_attributes">http://rubygems.org/gems/restricted_attributes</a></p>
<p><span style="color:#808000;"><strong>Installation and Configuration :</strong></span></p>
<p>1. Install restricted attributes plugin / gem :</p>
<p>- Install Plugin:</p>
<p>Download restricted_attributes plugin from above plugin link and add it your projects vendor directory.</p>
<p>- Install Gem :</p>
<p>You can install restricted_attributes gem, just add  following line in your project&#8217;s gemfile.</p>
<p><em>     gem &#8220;restricted_attributes&#8221;</em></p>
<p>2. Requirements (If you want to use :declarative tag feature) :</p>
<pre> - declarative_authorization plugin/gem.</pre>
<p>3.  permissions.yml</p>
<p>Create permissions.yml file in your project/config  folder. like,</p>
<pre>Format : /config/permissions.yml
    _____________________________________________________________
    |:default:
    |  :readonly: [:attribute1, :attribute2]
    |  :hiddenonly: [:attribute1, :attribute2]
    |  :createonly: [:attribute1, :attribute2]
    |  :updateonly: [:attribute1, :attribute2]
    |:role_1:
    |  :class_name_1:
    |    :readonly: [:attribute1, :attribute2]
    |    :hiddenonly: [:attribute1, :attribute2]
    |    :createonly: [:attribute1, :attribute2]
    |    :updateonly: [:attribute1, :attribute2]
    |    :permit_to: [:attribute1, :attribute2]
    |  :class_name_2:
    |    :permit_to: [:attribute1, :attribute2]
    |:role_2:
    |  :class_name_1:
    |    :permit_to: [:attribute1, :attribute2]
    |  :class_name_2:
    |    :permit_to: [:attribute1, :attribute2]
    |
    |
    |___________________________________________________________</pre>
<p>where :</p>
<ul>
<li> role_1, role_2 are the roles of user.</li>
<li>class_name_1, class_name_2 are the class name or Model name</li>
<li>readonly, hiddenonly, createonly, updateonly - To set restriction on specific role.</li>
<li>permit_to: [] feature to set permission to change value of added attributes.</li>
<li>default: provides common restricted attributes for all classes of all roles like id, create_at, updated_at.</li>
</ul>
<p>======================= Examples ============================</p>
<pre># Example 1 Simple one (without use of :declarative tag feature)
================================================================

    class Post &lt; ActiveRecord::Base
        has_restricted_attributes :read_only =&gt; [:status],
                            :create_only =&gt; [:title, :publish],
                            :update_only =&gt; [:tags],
			    :hidden_only =&gt; [:activated],
                            :read_only_message =&gt; "is a read only attribute",
                            :create_only_message =&gt; "can't update, its permitted to create only.",
                            :update_only_message =&gt; "can't add, its permitted to update only."
    end</pre>
<p>So, the restricted attributes will be as shown in following table.</p>
<p># Post Model :</p>
<table width="443" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td rowspan="2" valign="top" width="58">Can-&gt;</td>
<td colspan="2" valign="top" width="162">Read/Hidden Only):status/:activated</td>
<td colspan="2" valign="top" width="138">(Create Only):title,:publish</td>
<td colspan="2" valign="top" width="132">(Update Only):tags</td>
</tr>
<tr>
<td valign="top" width="66">Create</td>
<td valign="top" width="96">Update</td>
<td valign="top" width="66">Create</td>
<td valign="top" width="72">Update</td>
<td valign="top" width="72">Create</td>
<td valign="top" width="60">Update</td>
</tr>
<tr>
<td style="text-align:center;" valign="top" width="58"> Any User</td>
<td style="text-align:center;" valign="top" width="66">NO</td>
<td style="text-align:center;" valign="top" width="96">NO</td>
<td style="text-align:center;" valign="top" width="66">YES</td>
<td style="text-align:center;" valign="top" width="72">NO</td>
<td style="text-align:center;" valign="top" width="72">NO</td>
<td style="text-align:center;" valign="top" width="60">YES</td>
</tr>
</tbody>
</table>
<p>Console Output :<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<pre>    &gt;&gt; post = Post.new(:status =&gt; true, :title =&gt; "New Title", :tags =&gt; "new, topic")
    &gt;&gt; post.save
    =&gt; false

    &gt;&gt; post.errors
    =&gt; #&lt;OrderedHash {:status =&gt; ["is a read only attribute"], :tags=&gt;["can't add, its permitted to update only."]}&gt;

    # for hidden attributes
    &gt;&gt; post = Post.new(:activated =&gt; true)
    &gt;&gt; post.save
    =&gt; false

    &gt;&gt; post.errors
    =&gt; #&lt;OrderedHash {:status =&gt; ["is a hidden attribute"]}&gt;
    OR
    &gt;&gt; post.is_restricted?(:read, :activated)  # To check :activated field is restricted to read.
    =&gt; true</pre>
<p>===============================================================</p>
<pre># Example 2 : (with :declarative =&gt; true tag feature)
=====================================================

Step 1 :

    class User &lt; ActiveRecord::Base
        has_restricted_attributes :read_only =&gt; [:logged_in],
                            :create_only =&gt; [:login, :email],
                            :update_only =&gt; [:bio],
                            :declarative =&gt; true

    end

    class Post &lt; ActiveRecord::Base
        has_restricted_attributes :read_only =&gt; [:status],
                            :create_only =&gt; [:title, :publish],
                            :update_only =&gt; [:tags],
			    :hidden_only =&gt; [:activated],
                            :declarative =&gt; true,
                            :read_only_message =&gt; "is a read only attribute",
                            :create_only_message =&gt; "can't update, its permitted to create only.",
                            :update_only_message =&gt; "can't add, its permitted to update only."
    end</pre>
<p>Step 2 :<br />
Create permissions.yml file in your project/config/  folder,  and add roles and permissions for the user as shown in following table.</p>
<p>* Here you can set permission to change the value of restricted attributes on the basis of role system.</p>
<pre>Example:
    ## /config/permissions.yml
     ___________________________________________________________
    |:default:
    |  :readonly: [:created_at, :updated_at]
    |:global_admin:
    |  :user:
    |    :permit_to: [:logged_in, :login, :email, :bio]
    |  :post:
    |    :permit_to: [:title, :status, :publish, :tags]
    |:member:
    |  :user:
    |    :permit_to: [:email]
    |  :post:
    |    :permit_to: [:publish]
    |
    |
    |
    |
    |___________________________________________________________</pre>
<p>asdfasdf</p>
<p># where in that,</p>
<ul>
<li>:global_admin , :member are the roles of user. [ROLE]</li>
<li>:user , :post are the class names [CLASS/MODEL]</li>
<li>:permit_to: [] here you can add those attributes which will be permitted for appropriate User [ATTRIBUTES]</li>
<li>:default: you can add common attributes to restrict the access for all classes.</li>
</ul>
<p>Result :<br />
&#8212;&#8212;&#8212;</p>
<p>So, the permissions on restricted attributes for global_admin and member user will be as shown in following table.</p>
<p>#Post Model :</p>
<table width="408" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td rowspan="2" valign="top" width="106">        Can-&gt;</td>
<td style="text-align:center;" colspan="2" valign="top" width="132">(Read Only)<br />
:status</td>
<td style="text-align:center;" colspan="2" valign="top" width="178">(Create Only)<br />
:title,:publish</td>
<td style="text-align:center;" colspan="2" valign="top" width="130">(Update Only)<br />
:tags</td>
</tr>
<tr>
<td valign="top" width="66">Create</td>
<td valign="top" width="66">Update</td>
<td valign="top" width="66">Create</td>
<td valign="top" width="112">Update</td>
<td valign="top" width="62">Create</td>
<td valign="top" width="67">Update</td>
</tr>
<tr>
<td valign="top" width="106">
<p style="text-align:center;">User<br />
(global_admin)</p>
</td>
<td style="text-align:center;" valign="top" width="66">YES</td>
<td style="text-align:center;" valign="top" width="66">YES</td>
<td style="text-align:center;" valign="top" width="66">YES</td>
<td style="text-align:center;" valign="top" width="112">YES</td>
<td style="text-align:center;" valign="top" width="62">YES</td>
<td style="text-align:center;" valign="top" width="67">YES</td>
</tr>
<tr>
<td valign="top" width="106">
<p style="text-align:center;">User<br />
(member)</p>
</td>
<td style="text-align:center;" valign="top" width="66">NO</td>
<td style="text-align:center;" valign="top" width="66">NO</td>
<td style="text-align:center;" valign="top" width="66">YES</td>
<td style="text-align:center;" valign="top" width="112">NO-:title YES-:publish</td>
<td style="text-align:center;" valign="top" width="62">NO</td>
<td style="text-align:center;" valign="top" width="67">YES</td>
</tr>
</tbody>
</table>
<p>Console Output :<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<pre>    
    # for member user
    &gt;&gt; Authorization.current_user = User.find_by_login("member")
    &gt;&gt; post = Post.new(:status =&gt; true, :title =&gt; "New Title", :tags =&gt; "new, topic")
    &gt;&gt; post.publish = true
    &gt;&gt; post.save
    =&gt; false
    &gt;&gt; post.errors
    =&gt; &lt;OrderedHash {:status =&gt; ["is a read only attribute"], :tags =&gt; ["is a update only attribute"]}&gt;

    &gt;&gt; post = Post.find(123)
    &gt;&gt; post.title = "My new title"
    &gt;&gt; post.publish = false
    &gt;&gt; post.save
    =&gt; false

    &gt;&gt; post.errors
    =&gt; &lt;OrderedHash {:title =&gt; ["is a create only attribute"]}&gt;

    # for hidden attributes
    &gt;&gt; post = Post.new(:activated =&gt; true)
    &gt;&gt; post.save
    =&gt; false

    &gt;&gt; post.errors
    =&gt; #&lt;OrderedHash {:status =&gt; ["is a hidden attribute"]}&gt;
    OR
    &gt;&gt; post.is_restricted?(:read, :activated)  # To check :activated field is restricted to read.
    =&gt; true

    ### For Global Admin

    &gt;&gt; Authorization.current_user = User.find_by_login("global_admin")
    &gt;&gt; post = Post.new(:status =&gt; true, :title =&gt; "New Title", :tags =&gt; "new, topic")
    &gt;&gt; post.save
    =&gt; true

    &gt;&gt; post.errors
    =&gt; #&lt;OrderedHash {}&gt;</pre>
<p>======================= End Examples ============================</p>
<p><span style="color:#808000;">More information &amp; more examples refer in it&#8217;s <strong>Part 2  (Coming soon)</strong></span></p>
<p>Cheers!!! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thank you<br />
Ganesh K</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ganeshkathare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ganeshkathare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ganeshkathare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ganeshkathare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ganeshkathare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ganeshkathare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ganeshkathare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ganeshkathare.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=70&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ganeshkathare.wordpress.com/2011/08/30/rails-set-restriction-and-permission-on-attributes-at-model-level-based-on-role-system-using-restricted_attributes-plugin-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16d1c84dfa4f895919e8252ad869216f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ganeshkathare</media:title>
		</media:content>
	</item>
		<item>
		<title>rspec 2.5 with jruby 1.5.6 + rails 3</title>
		<link>http://ganeshkathare.wordpress.com/2011/05/30/rspec-2-5-with-jruby-1-5-6-rails-3/</link>
		<comments>http://ganeshkathare.wordpress.com/2011/05/30/rspec-2-5-with-jruby-1-5-6-rails-3/#comments</comments>
		<pubDate>Mon, 30 May 2011 10:30:12 +0000</pubDate>
		<dc:creator>Ganesh Kathare</dc:creator>
				<category><![CDATA[Jruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[jruby 1.5.6]]></category>
		<category><![CDATA[Rspec 2.5]]></category>
		<category><![CDATA[rspec 2.5 with jruby 1.5.6 + rails 3]]></category>
		<category><![CDATA[rspec rails 3]]></category>

		<guid isPermaLink="false">http://ganeshkathare.wordpress.com/?p=52</guid>
		<description><![CDATA[&#160; Here is one another post on rspec 2.5 with jruby 1.5.6 + rails 3 Installation steps : First of all I consider you have setup environment with jruby 1.5.6 + rails 3.0.6. You can download jruby 1.5.6 zip file from following link http://jruby.org.s3.amazonaws.com/downloads/1.5.6/jruby-bin-1.5.6.zip After environment  setup and configuration. Step 1 -  To install rspec gem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=52&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><strong>Here is one another post on rspec 2.5 with jruby 1.5.6 + rails 3</strong></p>
<p><strong>Installation steps :</strong></p>
<p>First of all I consider you have setup environment with jruby 1.5.6 + rails 3.0.6.</p>
<p>You can download jruby 1.5.6 zip file from following link</p>
<p><a href="http://jruby.org.s3.amazonaws.com/downloads/1.5.6/jruby-bin-1.5.6.zip">http://jruby.org.s3.amazonaws.com/downloads/1.5.6/jruby-bin-1.5.6.zip</a></p>
<p>After environment  setup and configuration.</p>
<p><strong>Step 1 -</strong>  To install rspec gem just add following lines in your Gemfile of your project.\</p>
<pre>group :development, :test do
  gem "rspec-rails", "&gt;= 2.0.1"
end</pre>
<p><strong>Step 2 -</strong> Try bundle install at project root</p>
<pre>&gt; bundle install</pre>
<p><strong>Step 3 -</strong>  Once you installed, then you need to install RSpec</p>
<pre>&gt; jruby -S  rails  g  rspec:install</pre>
<p>Output :</p>
<pre>exist  lib
create  lib/tasks/rspec.rake
exist  config/initializers
create  config/initializers/rspec_generator.rb
exist  spec
create  spec/spec_helper.rb</pre>
<p><strong>Step 4</strong> &#8211; install binstubs in your project.</p>
<pre>&gt; bundle install --binstubs</pre>
<p>This will create bin folder in your project directory ( like  <span style="text-decoration:underline;">urproject/bin/</span> )</p>
<p>and will auto generate all rspec bin stubs into that directory.</p>
<p>Like..</p>
<pre>autospec
cdiff
cucumber
decolor
edit_json.rb
erubis
htmldiff
image_voodoo
ldiff
memcached_top
mongrel_rpm
newrelic
newrelic_cmd
nokogiri
prettify_json.rb
rackup
rails
rake
rake2thor
rprotoc
rspec
ruby_parse
thor
tilt
tt</pre>
<p><strong>Step &#8211; 5  - </strong>Create test database</p>
<pre>&gt; rake db:test:clone_structure</pre>
<p>So this is all about rspec installation and configuration for your project.</p>
<p>&nbsp;</p>
<p><strong>Step &#8211; 6</strong> &#8211; <strong>Unit testing ( Model testing)</strong></p>
<p># spec/models/user_spec.rb</p>
<pre>require File.dirname(__FILE__) + '/../spec_helper'

context "User" do
  before(:each) do
   @user1 = User.new(:name =&gt; "Ganesh")
   @user2 = User.create(:name =&gt; "Ganesh K", :city =&gt; "Mumbai", :country =&gt; "India")
  end

  specify "should save" do
    lambda {
      @user1.city = "Navi Mumbai"
      @user1.country = "India"
      @user1.save.should be_true
    }.should change(User, :count).by(1)
  end
  specify "should not save" do
    lambda {
      @user1.save.should be_false
      @user1.errors.should_not be_empty
    }.should change(User, :count).by(0)
  end

  specify "should update" do
   lambda {
      @user2.city = "Pune"
      @user2.save.should be_true
      @user2.city.should == "Pune"
    }.should change(User, :count).by(0)
  end  

  specify "should destroy" do
    lambda {
      @user2.destroy.should be_true
    }.should change(User, :count).by(-1)
  end
end</pre>
<p>&nbsp;</p>
<p><strong>Step &#8211; 7</strong>  &#8211; <strong>Functional Testing ( Controller Testing)</strong></p>
<p># spec/controllers/users_controller_spec.rb</p>
<pre>require File.dirname(__FILE__) + '/../spec_helper'

describe UsersController do
  render_views

  before(:each) do
   @user1 = User.new(:name =&gt; "Ganesh")
   @user2 = User.create(:name =&gt; "Ganesh K", :city =&gt; "Mumbai", :country =&gt; "India")
  end

  specify "should be show index" do
    get :index
     response.should be_success
     assigns[:users].should_not be_blank
    end
  end

  specify "should create user." do
   lambda {
     post :create, {:user =&gt; {:name =&gt; "Ganesh", :city =&gt; "Latur", :country =&gt; "India"} }
     assigns[:user].should_not be_blank
     response.should redirect_to(users_path)
   }.should change(User, :count).by(1)
  end

  specify "should update user." do
   lambda {
     put :update, {:id =&gt; @user2.id, :user =&gt; {:city =&gt; "Pune"}}
     assigns[:user].should_not be_blank
     assigns[:user].city.should == "Pune"
     response.should redirect_to(users_path)
   }.should change(User, :count).by(0)
  end
  specify "should destroy user." do
    lambda {
     post :destroy, {:id =&gt; @user2.id}
     response.should redirect_to(users_path)
    }.should change(User, :count).by(-1)
  end
end</pre>
<p>======================================</p>
<p>You can refer following few rspec command to test your model / controller files are like.</p>
<p><span style="color:#ff0000;">To test model</span></p>
<pre>&gt; jruby -S bin/rspec spec/models/user_spec.rb</pre>
<p><span style="color:#ff0000;">To  test controller</span></p>
<pre>&gt; jruby -S bin/rspec spec/controllers/users_controller_spec.rb</pre>
<p><span style="color:#ff0000;">To test all model spec files with single command.</span></p>
<pre>&gt; jruby -S bin/rspec spec/models</pre>
<p><span style="color:#ff0000;">To test all controller spec files with single command.</span></p>
<pre>&gt; jruby -S bin/rspec spec/controllers</pre>
<p>Cheersss!!!!</p>
<p>-Ganesh K</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ganeshkathare.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ganeshkathare.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ganeshkathare.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ganeshkathare.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ganeshkathare.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ganeshkathare.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ganeshkathare.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ganeshkathare.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=52&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ganeshkathare.wordpress.com/2011/05/30/rspec-2-5-with-jruby-1-5-6-rails-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16d1c84dfa4f895919e8252ad869216f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ganeshkathare</media:title>
		</media:content>
	</item>
		<item>
		<title>Rails 3 named_scope deprecation warning</title>
		<link>http://ganeshkathare.wordpress.com/2010/12/31/rails-3-named_scope-deprecation-warning/</link>
		<comments>http://ganeshkathare.wordpress.com/2010/12/31/rails-3-named_scope-deprecation-warning/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 06:13:30 +0000</pubDate>
		<dc:creator>Ganesh Kathare</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[named_scope deprecation warning]]></category>
		<category><![CDATA[Rails 3 named_scope]]></category>
		<category><![CDATA[Rails 3 named_scope deprecation warning]]></category>

		<guid isPermaLink="false">http://ganeshkathare.wordpress.com/?p=38</guid>
		<description><![CDATA[Rails 3 named_scope Slit difference named_scope syntax between Rails 2 and Rails 3 Rails 2.X : class User &#60; ActiveRecord::Base named_scope :newest_user, :conditions =&#62; ["created_at &#62;= ?", (Time.now.utc - 1.hour)] end Rails 3.x : class User &#60; ActiveRecord::Base scope :newest_user, :conditions =&#62; ["created_at &#62;= ?", (Time.now.utc - 1.hour)] end So, to avoid deprecation warning of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=38&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Rails 3 named_scope</h3>
<p><strong><em>Slit difference named_scope syntax between Rails 2 and Rails 3</em></strong></p>
<p><strong>Rails 2.X :</strong></p>
<p>class User &lt; ActiveRecord::Base</p>
<p>named_scope :newest_user, :conditions =&gt; ["created_at &gt;= ?", (Time.now.utc - 1.hour)]</p>
<p>end</p>
<p><strong>Rails 3.x :</strong><br />
<code><br />
class User &lt; ActiveRecord::Base</code></p>
<p>scope :newest_user, :conditions =&gt; ["created_at &gt;= ?", (Time.now.utc - 1.hour)]</p>
<p>end</p>
<p><strong><em>So, to avoid deprecation warning of &#8220;named_scope&#8221; in Rails 3.x just use &#8220;scope&#8221;.</em></strong></p>
<p><strong><em>Good Luck <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ganeshkathare.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ganeshkathare.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ganeshkathare.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ganeshkathare.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ganeshkathare.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ganeshkathare.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ganeshkathare.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ganeshkathare.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=38&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ganeshkathare.wordpress.com/2010/12/31/rails-3-named_scope-deprecation-warning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16d1c84dfa4f895919e8252ad869216f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ganeshkathare</media:title>
		</media:content>
	</item>
		<item>
		<title>RoR sms api integration</title>
		<link>http://ganeshkathare.wordpress.com/2010/12/24/ror-sms-api-integration/</link>
		<comments>http://ganeshkathare.wordpress.com/2010/12/24/ror-sms-api-integration/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 15:20:06 +0000</pubDate>
		<dc:creator>Ganesh Kathare</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[rails sms api integration]]></category>
		<category><![CDATA[ruby on rails sms api]]></category>
		<category><![CDATA[ruby send sms]]></category>

		<guid isPermaLink="false">http://ganeshkathare.wordpress.com/?p=33</guid>
		<description><![CDATA[SMS Integration : For my project, I integrated this service for Mobile number Verification. In desinged module user can verify his mobile no by verification code. I got Paid service to send SMS from my application(service provider www.znisms.com) Required Parameters to integrate this service are: 1 &#8211; userId 2-API key 3-senderID 4-sendto 5-message In that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=33&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>SMS Integration :</strong><br />
For my project, I integrated this service for Mobile number Verification. In desinged module user can verify his mobile no by verification code. I got Paid service to send SMS from my application(service provider www.znisms.com)</p>
<p><strong>Required Parameters to integrate this service are:</strong><br />
1 &#8211; userId<br />
2-API key<br />
3-senderID<br />
4-sendto<br />
5-message In that first</p>
<p>3 parameters will get from service provider..</p>
<p>After that, In an action you have to create url with this parameters &amp; related values<br />
like ## /controller/profiles_controller.rb</p>
<pre>def send_sms
  @receiver = params[:users][:reciever]
  @msg = params[:users][:message]
  @mu_sms_url = "http://api.znisms.com/post/smsv3.asp? userid=GaneshK&amp;apikey=xxx&amp;message=#{@msg}&amp; senderid=9123123456&amp;sendto=#{@receiver}"
  Kernal.open(@mu_sms_url) do |f|
    @result = f.write
  end
  flash[:notice] = @result
  redirect_to @user
 end</pre>
<p>So, by using above code you can send request, Purpose behind this API key is unique key, and that is used to validate authorized request access.</p>
<p>Hope this code will help for your application.</p>
<p>Regards,<br />
-Ganesh Kathare.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ganeshkathare.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ganeshkathare.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ganeshkathare.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ganeshkathare.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ganeshkathare.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ganeshkathare.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ganeshkathare.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ganeshkathare.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=33&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ganeshkathare.wordpress.com/2010/12/24/ror-sms-api-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16d1c84dfa4f895919e8252ad869216f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ganeshkathare</media:title>
		</media:content>
	</item>
		<item>
		<title>Rails3 after_commit</title>
		<link>http://ganeshkathare.wordpress.com/2010/12/24/rails3-after_commit/</link>
		<comments>http://ganeshkathare.wordpress.com/2010/12/24/rails3-after_commit/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 12:24:24 +0000</pubDate>
		<dc:creator>Ganesh Kathare</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[after_commit﻿ callback]]></category>
		<category><![CDATA[rails 3 after_commit﻿]]></category>
		<category><![CDATA[rails 3 calllback]]></category>

		<guid isPermaLink="false">http://ganeshkathare.wordpress.com/?p=17</guid>
		<description><![CDATA[Rails 3  after_commit﻿ callback: In rails 3 after_commit gem&#8217;s all functionality is now natively available in its library. There is some syntax variation in Rails 2 and Rails 3 as follow Syntax in Rails 3 : # commit after every save after_commit :my_method # commit after on save record after_commit :my_method : on =&#62; :create [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=17&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font size="6">Rails 3  after_commit﻿ callback:</font></strong></p>
<p>In rails 3 after_commit gem&#8217;s all functionality is now natively available in its library. There is some syntax variation in Rails 2 and Rails 3 as follow</p>
<p><strong>Syntax in Rails 3 :</strong></p>
<p style="padding-left:30px;"># commit after every save<br />
after_commit :my_method</p>
<p style="padding-left:30px;"># commit after on save record<br />
after_commit :my_method : on =&gt; :create</p>
<p style="padding-left:30px;"># commit after on update record<br />
after_commit :my_method : on =&gt; :update</p>
<p style="padding-left:30px;"># commit after on delete record<br />
after_commit :my_method : on =&gt; :destroy</p>
<p><strong>Syntax in Rails 2 :</strong></p>
<p style="padding-left:30px;"># commit after every save<br />
after_commit :my_method</p>
<p style="padding-left:30px;"># commit after on save record<br />
after_commit_on_create :my_method</p>
<p style="padding-left:30px;"># commit after on update record<br />
after_commit_on_update :my_method</p>
<p style="padding-left:30px;"># commit after on delete record<br />
after_commit_on_destroy :my_method</p>
<p>&nbsp;</p>
<p>So, for rails 3 now no need to install any gem or plugin of after_commit.</p>
<p>Good Luck <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ganeshkathare.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ganeshkathare.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ganeshkathare.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ganeshkathare.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ganeshkathare.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ganeshkathare.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ganeshkathare.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ganeshkathare.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ganeshkathare.wordpress.com&amp;blog=8367558&amp;post=17&amp;subd=ganeshkathare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ganeshkathare.wordpress.com/2010/12/24/rails3-after_commit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16d1c84dfa4f895919e8252ad869216f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ganeshkathare</media:title>
		</media:content>
	</item>
	</channel>
</rss>
