summaryrefslogtreecommitdiff
path: root/qa/qa/factory/product.rb
blob: 34df0bda8e5152f294457a0907bd030b721950b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'capybara/dsl'

module QA
  module Factory
    class Product
      include Capybara::DSL

      attr_reader :factory

      def initialize(factory)
        @factory = factory

        define_attributes
      end

      def visit!
        visit(web_url)
      end

      def populate(*attributes)
        attributes.each(&method(:public_send))
      end

      private

      def define_attributes
        factory.class.attributes_names.each do |name|
          define_singleton_method(name) do
            factory.public_send(name)
          end
        end
      end
    end
  end
end