Sha256: 23d8cb285e81e237b9ae2daa77747db10e2de942e10a3772f80a699a76e004cb

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

module SocialStream
  module TestHelpers
    module Controllers
      # Post for PostsController
      def model_class
        @model_class ||=
          described_class.to_s.sub!("Controller", "").singularize.constantize
      end

      # :post for PostsController
      def model_sym
        @model_sym ||=
          model_class.to_s.underscore.to_sym
      end

      # Factory.attributes_for(:post) for PostsController
      def model_attributes
        @model_attributes ||=
          Factory.attributes_for(model_sym)
      end

      def attributes
        { model_sym => model_attributes }
      end

      # Post.count
      def model_count
        model_class.count
      end

      def model_assigned_to tie
        model_attributes[:_activity_tie_id] = tie.id
      end

      shared_examples_for "Allow Creating" do
        it "should create" do
          count = model_count
          post :create, attributes

          resource = assigns(model_sym)

          model_count.should eq(count + 1)
          assert resource.valid?
          response.should redirect_to(resource)
        end
      end

      shared_examples_for "Deny Creating" do
        it "should not create" do
          count = model_count
          begin
            post :create, attributes
          rescue CanCan::AccessDenied
          end

          resource = assigns(model_sym)

          model_count.should eq(count)
          resource.should be_new_record
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
social_stream-0.4.2 lib/social_stream/test_helpers/controllers.rb
social_stream-0.4.1 lib/social_stream/test_helpers/controllers.rb
social_stream-0.4.0 lib/social_stream/test_helpers/controllers.rb