Sha256: 284859a846ef5c15670c6d1bde7a2285369ae3db775d2673730bed1bc32a6c1a

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

RSpec.shared_context('repo') do
  include_context 'models'
  include_context 'mappers'

  let(:repo) { repo_class.new(rom) }

  let(:repo_class) do
    Class.new(ROM::Repository[:users]) do
      relations :tasks, :tags, :posts, :labels, :posts_labels, :books, :authors

      def find_users(criteria)
        users.find(criteria)
      end

      def all_users
        users.all
      end

      def all_users_as_users
        users.as(:user).all
      end

      def users_with_tasks
        aggregate(many: { all_tasks: tasks.for_users })
      end

      def users_with_tasks_and_tags
        aggregate(many: { all_tasks: tasks_with_tags(tasks.for_users) })
      end

      def users_with_task
        aggregate(one: tasks)
      end

      def users_with_task_by_title(title)
        aggregate(one: tasks.find(title: title))
      end

      def users_with_posts_and_their_labels
        users.combine(posts: [:labels])
      end

      def posts_with_labels
        posts.combine_children(many: labels)
      end

      def label_with_posts
        labels.combine_children(one: posts)
      end

      def tasks_for_users(users)
        tasks.for_users(users)
      end

      def task_with_user
        tasks.find(tasks[:id].qualified => 2).wrap_parent(user: users)
      end

      def task_with_owner
        tasks.find(id: 2).combine_parents(one: { owner: users })
      end

      def tasks_with_tags(tasks = self.tasks)
        tasks.combine_children(many: tags)
      end

      def tag_with_wrapped_task
        tags.wrap_parent(task: tasks)
      end
    end
  end

  let(:comments_repo) do
    Class.new(ROM::Repository[:comments]) do
      relations :likes

      def comments_with_likes
        aggregate(many: { likes: likes })
      end

      def comments_with_emotions
        root.combine(:emotions)
      end
    end.new(rom)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-repository-1.4.0 spec/shared/repo.rb
rom-repository-1.3.3 spec/shared/repo.rb
rom-repository-1.3.2 spec/shared/repo.rb