Module: ActiveRecord::LiteView::Etest

Defined in:
lib/vex/active_record/lite_view.rb

Defined Under Namespace

Classes: Holder

Instance Method Summary collapse

Instance Method Details

#test_lite_viewObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/vex/active_record/lite_view.rb', line 117

def test_lite_view
  db = ActiveRecord::Base.connection

  Holder.create!
  Holder.create!
  Holder.create!

  assert_equal(3, Holder.count)
  
  # -- create a view
  Holder.has_view :view_dummy, "SELECT id AS holder_id, 1 AS count_all FROM holders"
  assert_equal("1", Holder.first.view_dummy.count_all)

  # -- doesnt recreate identical view
  # TODO: Check that an identical view won't be recreated
  # Holder.has_view :view_dummy, "SELECT id AS holder_id, 1 AS count_all FROM holders"
  
  assert_equal("1", Holder.first.view_dummy.count_all)

  # -- create a slightly different view
  Holder.has_view :view_dummy, "SELECT id AS holder_id, 2 AS count_all FROM holders"
  assert_equal("2", Holder.first.view_dummy.count_all)
end