Sha256: 449869abf703a32edeb63c2ca5302f38965b2dd78239a341ba47a1f1b6a98339

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

module Spec
  module Rails
    module Matchers
      def belong_to(association)
        return simple_matcher("model to belong to #{association}") do |model|
          model = model.class if model.is_a? ActiveRecord::Base
          model.reflect_on_all_associations(:belongs_to).find { |a| a.name == association }
        end
      end

      def have_many(association)
        return simple_matcher("model to have many #{association}") do |model|
          model = model.class if model.is_a? ActiveRecord::Base
          model.reflect_on_all_associations(:has_many).find { |a| a.name == association }
        end
      end

      def have_one(association)
        return simple_matcher("model to have one #{association}") do |model|
          model = model.class if model.is_a? ActiveRecord::Base
          model.reflect_on_all_associations(:has_one).find { |a| a.name == association }
        end
      end

      def have_and_belong_to_many(association)
        return simple_matcher("model to have and belong to many #{association}") do |model|
          model = model.class if model.is_a? ActiveRecord::Base
          model.reflect_on_all_associations(:has_and_belongs_to_many).find { |a| a.name == association }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec-on-rails-matchers/lib/spec/rails/matchers/associations.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec-on-rails-matchers/lib/spec/rails/matchers/associations.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec-on-rails-matchers/lib/spec/rails/matchers/associations.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec-on-rails-matchers/lib/spec/rails/matchers/associations.rb
saturnflyer-rspec-rails-matchers-1.0.0 lib/spec/rails/matchers/associations.rb
saturnflyer-rspec-rails-matchers-1.0.1 lib/spec/rails/matchers/associations.rb