split_cat 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -11
  3. data/app/controllers/split_cat/experiments_controller.rb +45 -7
  4. data/app/helpers/split_cat/experiments_helper.rb +1 -4
  5. data/app/models/split_cat/experiment.rb +3 -21
  6. data/app/views/split_cat/experiments/_form.html.erb +31 -12
  7. data/app/views/split_cat/experiments/_search.html.erb +8 -0
  8. data/app/views/split_cat/experiments/edit.html.erb +6 -0
  9. data/app/views/split_cat/experiments/index.html.erb +4 -0
  10. data/app/views/split_cat/experiments/new.html.erb +5 -0
  11. data/config/locales/en.yml +0 -2
  12. data/config/routes.rb +1 -1
  13. data/lib/split_cat/helpers.rb +8 -0
  14. data/lib/split_cat/version.rb +1 -1
  15. data/spec/controllers/split_cat/experiments_controller_spec.rb +146 -50
  16. data/spec/data/helpers/experiment_info.html +1 -1
  17. data/spec/data/helpers/experiment_info.html.tmp +1 -1
  18. data/spec/data/helpers/experiment_table.html +1 -1
  19. data/spec/data/helpers/experiment_table.html.tmp +1 -1
  20. data/spec/dummy/db/development.sqlite3 +0 -0
  21. data/spec/dummy/log/development.log +1008 -0
  22. data/spec/dummy/log/test.log +58637 -0
  23. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  24. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  25. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  26. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  27. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  28. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  29. data/spec/dummy/tmp/pids/server.pid +1 -0
  30. data/spec/helpers/split_cat/experiments_helper_spec.rb +1 -1
  31. data/spec/models/split_cat/experiment_spec.rb +5 -44
  32. data/spec/routing/split_cat/experiments_routing_spec.rb +39 -0
  33. data/spec/spec_helper.rb +6 -0
  34. data/spec/support/stub_view_routes.rb +3 -1
  35. data/spec/views/split_cat/experiments/edit.html.erb_spec.rb +16 -0
  36. data/spec/views/split_cat/experiments/index.html.erb_spec.rb +8 -7
  37. data/spec/views/split_cat/experiments/new.html.erb_spec.rb +16 -0
  38. data/spec/views/split_cat/experiments/show.html.erb_spec.rb +6 -8
  39. metadata +24 -55
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4ac33764ebe4f87592a6751aacdd7db63eac155
4
- data.tar.gz: 8537f5354b592c3c0bc9ae9ca4600b15dc41a1fc
3
+ metadata.gz: 4880681278c9fc6b8581039569aee279d717ca70
4
+ data.tar.gz: 4ec902b130f34eded678960ed766897ad2514726
5
5
  SHA512:
6
- metadata.gz: 0ecb731b83eda634900c91d2580a45321e757bb1dafe525561b3ea495645f8147b15f80881118a474d09efa1163ec814704ffb0f84ff7627cbeffcacf9297a51
7
- data.tar.gz: 59b40325906f5a2e75edf644df830877cef6aa02096f1fd157eb8597b12f8d99b776bf3cbc85dea37bc2de683ad63e030cee001abad1a17e3cb60d2ec4a86121
6
+ metadata.gz: fc167cf4abce19f129ff514b18faa9a3ba5d34ebcdf7ddf92b5ddfb855e7bbc716678901a791786a128d45790e7878f27c473402030848e95e7cd587ac652d7e
7
+ data.tar.gz: 73600eff04eeb93dc395332a2eff862fa6dbb43e82a5af05715e9c378b5c6c397149c4b43b8482b9571373891bccd2f20db94140e62d9e27cc8d4bb2bfcde4a0
data/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ [![Gem Version](https://badge.fury.io/rb/split_cat.png)](http://badge.fury.io/rb/split_cat)
2
+ [![Build Status](https://travis-ci.org/schrodingersbox/split_cat.png?branch=master)](https://travis-ci.org/schrodingersbox/split_cat)
3
+ [![Dependency Status](https://gemnasium.com/schrodingersbox/split_cat.png)](https://gemnasium.com/schrodingersbox/split_cat)
4
+ [![Code Climate](https://codeclimate.com/github/schrodingersbox/split_cat.png)](https://codeclimate.com/github/schrodingersbox/split_cat)
5
+ [![Coverage Status](https://coveralls.io/repos/schrodingersbox/split_cat/badge.png)](https://coveralls.io/r/schrodingersbox/split_cat)
6
+
1
7
  # schrodingersbox/split_cat
2
8
 
3
9
  This Rails engine provides a framework for split testing.
@@ -43,6 +49,16 @@ See [The one line split-test, or how to A/B all the time](http://www.startupless
43
49
 
44
50
  ## How To
45
51
 
52
+ ### Apply Security To Reports
53
+
54
+ Modify `config.application.rb` to inject your authorization filter into the controller:
55
+
56
+ config.after_initialize do
57
+ SplitCat::ExperimentsController.instance_eval do
58
+ before_filter :require_login
59
+ end
60
+ end
61
+
46
62
  ### Create A New Experiment
47
63
 
48
64
  Create or add to `config/initializers/split_cat.rb`:
@@ -67,7 +83,7 @@ Create partials for each hypothesis. e.g. `button_a.html.erb` and `button_b.htm
67
83
 
68
84
  When rendering the partial, scope it with the experiment:
69
85
 
70
- render :partial => split_cat_scoped( :my_first_experiment, token, 'button' )
86
+ render :partial => split_cat_scoped( 'button', :my_first_experiment, token )
71
87
 
72
88
  This will cause the partial to use the hypothesis assigned for the user/token.
73
89
 
@@ -93,16 +109,6 @@ To use an externally defined token:
93
109
 
94
110
  split_cat_token( external_token )
95
111
 
96
- ### Apply Security To Reports
97
-
98
- Modify `config.application.rb` to inject your authorization filter into the controller:
99
-
100
- config.after_initialize do
101
- SplitCat::ExperimentsController.instance_eval do
102
- before_filter :require_login
103
- end
104
- end
105
-
106
112
  ## Best Practices
107
113
 
108
114
  ### Use A Constant Experiment ID
@@ -159,12 +165,16 @@ using multiple user accounts.
159
165
  * [FactoryGirl](https://github.com/thoughtbot/factory_girl)
160
166
  * [Shoulda](https://github.com/thoughtbot/shoulda-matchers)
161
167
  * [The one line split-test, or how to A/B all the time](http://www.startuplessonslearned.com/2008/09/one-line-split-test-or-how-to-ab-all.html)
168
+ * [Add Achievement Badges to Your Gem README](http://elgalu.github.io/2013/add-achievement-badges-to-your-gem-readme/)
162
169
 
163
170
  ## TODO
164
171
 
172
+ * Rework Experiment::factory to use template over DB, but fall back to DB
173
+
165
174
  * Spec rake tasks
166
175
 
167
176
  * As needed
177
+ * Add pagination to admin
168
178
  * Add a goals controller with action to record goal and redirect
169
179
  * Add split test probability calculator
170
180
  * hypo.control - boolean flag to determine which is baseline
@@ -1,18 +1,17 @@
1
1
  module SplitCat
2
2
  class ExperimentsController < ApplicationController
3
+ before_action :set_experiment, only: [:show, :edit, :update, :destroy]
3
4
 
4
- before_action :set_experiment, :only => [ :show ]
5
-
5
+ # GET /experiments
6
6
  def index
7
7
  @name = params[ :name ]
8
8
  @active = ( params[ :active ] == '1' )
9
9
 
10
10
  @experiments = Experiment.order( 'id desc' )
11
11
  @experiments = @experiments.where( 'name like ?', '%' + @name + '%') if @name
12
-
13
- @experiments = @experiments.map { |e| e.active? ? e : nil }.compact if @active
14
12
  end
15
13
 
14
+ # GET /experiments/1
16
15
  def show
17
16
  respond_to do |format|
18
17
  format.html
@@ -20,11 +19,50 @@ module SplitCat
20
19
  end
21
20
  end
22
21
 
23
- private
22
+ # GET /experiments/new
23
+ def new
24
+ @experiment = Experiment.new
25
+ end
26
+
27
+ # GET /experiments/1/edit
28
+ def edit
29
+ end
30
+
31
+ # POST /experiments
32
+ def create
33
+ @experiment = Experiment.new(experiment_params)
24
34
 
25
- def set_experiment
26
- @experiment = Experiment.includes( :goals, :hypotheses ).find( params[ :id ] )
35
+ if @experiment.save
36
+ redirect_to @experiment, notice: 'Experiment was successfully created.'
37
+ else
38
+ render action: 'new'
39
+ end
27
40
  end
28
41
 
42
+ # PATCH/PUT /experiments/1
43
+ def update
44
+ if @experiment.update(experiment_params)
45
+ redirect_to @experiment, notice: 'Experiment was successfully updated.'
46
+ else
47
+ render action: 'edit'
48
+ end
49
+ end
50
+
51
+ # DELETE /experiments/1
52
+ def destroy
53
+ @experiment.destroy
54
+ redirect_to experiments_url, notice: 'Experiment was successfully destroyed.'
55
+ end
56
+
57
+ private
58
+ # Use callbacks to share common setup or constraints between actions.
59
+ def set_experiment
60
+ @experiment = Experiment.includes( :goals, :hypotheses ).find(params[:id])
61
+ end
62
+
63
+ # Only allow a trusted parameter "white list" through.
64
+ def experiment_params
65
+ params[:experiment].permit( Experiment.new.attributes.keys )
66
+ end
29
67
  end
30
68
  end
@@ -60,7 +60,6 @@ module SplitCat
60
60
  concat experiment_info_row( :name, experiment.name )
61
61
  concat experiment_info_row( :description, experiment.description )
62
62
  concat experiment_info_row( :created, experiment.created_at )
63
- concat experiment_info_row( :active, experiment.active? )
64
63
  concat experiment_info_row( :subjects, number_with_delimiter( experiment.total_subjects ) )
65
64
  end
66
65
  end
@@ -117,7 +116,7 @@ module SplitCat
117
116
  end
118
117
 
119
118
  def experiment_search_form( name, active)
120
- render :partial => 'form', :locals => { :name => name, :active => active }
119
+ render :partial => 'search', :locals => { :name => name, :active => active }
121
120
  end
122
121
 
123
122
  def experiment_table( experiments )
@@ -125,7 +124,6 @@ module SplitCat
125
124
  output = content_tag( :tr ) do
126
125
  concat content_tag( :th, t( :id, :scope => :split_cat ) )
127
126
  concat content_tag( :th, t( :name, :scope => :split_cat ) )
128
- concat content_tag( :th, t( :active, :scope => :split_cat ) )
129
127
  end
130
128
 
131
129
  show = t( :show, :scope => :split_cat )
@@ -134,7 +132,6 @@ module SplitCat
134
132
  output += content_tag( :tr ) do
135
133
  concat content_tag( :td, experiment.id )
136
134
  concat content_tag( :td, experiment.name )
137
- concat content_tag( :td, experiment.active? )
138
135
  concat content_tag( :td, link_to( show, { :controller => :experiments, :action => :show, :id => experiment.id } ) )
139
136
  end
140
137
  end
@@ -12,13 +12,6 @@ module SplitCat
12
12
 
13
13
  belongs_to :winner, :class_name => Hypothesis
14
14
 
15
- # An experiment is only valid if it matches the current configuration
16
-
17
- def active?
18
- return false unless template = SplitCat.config.template( name )
19
- return !!same_structure?( template )
20
- end
21
-
22
15
  # Returns a memoized array of goal name => hypothesis_name => subject counts
23
16
 
24
17
  def goal_counts
@@ -154,22 +147,11 @@ module SplitCat
154
147
  return experiment
155
148
  end
156
149
 
157
- unless template = SplitCat.config.template( name )
158
- Rails.logger.error( "Experiment.factory not configured for experiment: #{name}" )
159
- return nil
160
- end
161
-
150
+ template = SplitCat.config.template( name )
162
151
  if experiment = Experiment.includes( :goals, :hypotheses ).find_by_name( name )
163
- unless experiment.same_structure?( template )
164
- experiment = nil
165
- Rails.logger.error( "Experiment.factory mismatched experiment: #{name}" )
166
- end
152
+ return nil if template && !experiment.same_structure?( template )
167
153
  else
168
- if template.save
169
- experiment = template
170
- else
171
- Rails.logger.error( "Experiment.factory failed to save experiment: #{name}" )
172
- end
154
+ experiment = template if template && template.save
173
155
  end
174
156
 
175
157
  @@cache[ name.to_sym ] = experiment
@@ -1,13 +1,32 @@
1
- <%= form_tag( '', :method => :get ) do %>
2
- <p>
3
- <%= label_tag( :name, t( :name, :scope => :split_cat ) ) %>
4
- <%= text_field_tag( :name, name ) %>
5
- </p>
6
-
7
- <p>
8
- <%= check_box_tag( :active, 1, active ) %>
9
- <%= label_tag( :active, t( :active_only, :scope => :split_cat ) ) %>
10
- </p>
11
-
12
- <%= submit_tag( t( :search, :scope => :split_cat ) ) %>
1
+ <%= form_for(@experiment) do |f| %>
2
+ <% if @experiment.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@experiment.errors.count, "error") %> prohibited this experiment from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @experiment.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="form-group">
15
+ <%= f.label( :name ) %>
16
+ <%= f.text_field( :name, :size => 32 ) %>
17
+ </div>
18
+
19
+ <div class="form-group">
20
+ <%= f.label( :description ) %>
21
+ <%= f.text_area( :description, :size => "60x10" ) %>
22
+ </div>
23
+
24
+ <div class="form-group">
25
+ <%= f.label( :winner_id ) %>
26
+ <%= f.text_field( :winner_id, :size => 8 ) %>
27
+ </div>
28
+
29
+ <div class="actions">
30
+ <%= f.submit %>
31
+ </div>
13
32
  <% end %>
@@ -0,0 +1,8 @@
1
+ <%= form_tag( '', :method => :get ) do %>
2
+ <p>
3
+ <%= label_tag( :name, t( :name, :scope => :split_cat ) ) %>
4
+ <%= text_field_tag( :name, name ) %>
5
+ </p>
6
+
7
+ <%= submit_tag( t( :search, :scope => :split_cat ) ) %>
8
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing experiment</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @experiment %> |
6
+ <%= link_to 'Back', experiments_path %>
@@ -3,3 +3,7 @@
3
3
 
4
4
  <h2><%= t( :search, :scope => :split_cat ) %></h2>
5
5
  <%= experiment_search_form( @name, @active) %>
6
+
7
+ <br>
8
+
9
+ <%= link_to 'New Experiment', new_experiment_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New experiment</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', experiments_path %>
@@ -1,7 +1,5 @@
1
1
  en:
2
2
  split_cat:
3
- active: active
4
- active_only: active only
5
3
  created: created
6
4
  description: description
7
5
  experiment: Experiment
data/config/routes.rb CHANGED
@@ -2,6 +2,6 @@ SplitCat::Engine.routes.draw do
2
2
 
3
3
  root :to => 'experiments#index'
4
4
 
5
- resources :experiments, :only => [ :index, :show ]
5
+ resources :experiments
6
6
 
7
7
  end
@@ -45,6 +45,14 @@ module SplitCat
45
45
  # #set_split_cat_cookie
46
46
 
47
47
  def set_split_cat_cookie( options = {} )
48
+
49
+ # Create a Subject for the cookie token, if it doesn't exist
50
+
51
+ if cookies[ :split_cat_token ] && cookies[ :split_cat_token ][ :value ] &&
52
+ !Subject.where( :token => cookies[ :split_cat_token ][ :value ] ).first
53
+ split_cat_token( cookies[ :split_cat_token ] )
54
+ end
55
+
48
56
  if options[ :force ] || !cookies[ :split_cat_token ]
49
57
  expires = SplitCat.config.cookie_expiration.from_now
50
58
  cookies[ :split_cat_token ] = { :value => split_cat_token, :expires => expires }
@@ -1,3 +1,3 @@
1
1
  module SplitCat
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -1,80 +1,176 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SplitCat::ExperimentsController do
3
+ module SplitCat
4
+ describe ExperimentsController do
4
5
 
5
- routes { SplitCat::Engine.routes }
6
+ routes { SplitCat::Engine.routes }
6
7
 
7
- it 'is a subclass of ApplicationController' do
8
- @controller.should be_a_kind_of( ApplicationController )
9
- end
10
-
11
- before( :each ) do
12
- @experiment = FactoryGirl.create( :experiment_full )
13
- controller.stub( :require_login )
14
- end
15
-
16
- describe '/index' do
8
+ let( :experiment ) { FactoryGirl.create( :experiment_full ) }
9
+ let(:valid_attributes) { { :name => 'valid' } }
10
+ let(:valid_session) { {} }
17
11
 
18
- it 'gets successfully' do
19
- get :index
20
- response.should be_success
12
+ it 'is a subclass of ApplicationController' do
13
+ @controller.should be_a_kind_of( ApplicationController )
21
14
  end
22
15
 
23
- it 'assigns experiments' do
24
- get :index
25
- response.should be_success
26
- expect( assigns( :experiments ) ).to be_present
16
+ before( :each ) do
17
+ controller.stub( :require_login )
18
+ expect( experiment ).to be_present
27
19
  end
28
20
 
29
- it 'accepts name and active params' do
30
- name = @experiment.name
31
- active = '1'
32
- get :index, :name => name, :active => active
21
+ describe "GET index" do
22
+ it "assigns all experiments as @experiments" do
23
+ get :index, {}, valid_session
24
+ assigns(:experiments).should eq([experiment])
25
+ end
26
+
27
+ it 'accepts name and active params' do
28
+ name = experiment.name
29
+ active = '1'
30
+ get :index, :name => name, :active => active
33
31
 
34
- expect( assigns( :name ) ).to be( name )
35
- expect( assigns( :active ) ).to eql( active == '1' )
32
+ expect( assigns( :name ) ).to be( name )
33
+ expect( assigns( :active ) ).to eql( active == '1' )
34
+ end
36
35
  end
37
36
 
38
- end
37
+ describe "GET show" do
38
+ it "assigns the requested experiment as @experiment" do
39
+ get :show, {:id => experiment.to_param}, valid_session
40
+ assigns(:experiment).should eq(experiment)
41
+ end
39
42
 
40
- describe '/show' do
43
+ context 'formatting CSV' do
41
44
 
42
- it 'gets successfully' do
43
- get :show, :id => @experiment.id
44
- response.should be_success
45
- end
45
+ it 'renders CSV' do
46
+ get :show, :id => experiment.id, :format => 'csv'
47
+ response.should be_success
48
+ response.content_type.should eql( 'text/csv' )
49
+ end
50
+
51
+ it 'turns the requested experiment into CSV' do
52
+ get :show, :id => experiment.id, :format => 'csv'
53
+ response.body.should eql( experiment.to_csv )
54
+ end
55
+
56
+ end
46
57
 
47
- it 'assigns experiments' do
48
- get :show, :id => @experiment.id
49
- response.should be_success
50
- expect( assigns( :experiment ) ).to be_present
58
+ context 'formatting HTML' do
59
+
60
+ it 'renders HTML' do
61
+ get :show, :id => experiment.id, :format => 'html'
62
+ response.should be_success
63
+ response.content_type.should eql( 'text/html' )
64
+ end
65
+
66
+ end
51
67
  end
52
68
 
53
- context 'formatting CSV' do
69
+ describe "GET new" do
70
+ it "assigns a new experiment as @experiment" do
71
+ get :new, {}, valid_session
72
+ assigns(:experiment).should be_a_new(Experiment)
73
+ end
74
+ end
54
75
 
55
- it 'renders CSV' do
56
- get :show, :id => @experiment.id, :format => 'csv'
57
- response.should be_success
58
- response.content_type.should eql( 'text/csv' )
76
+ describe "GET edit" do
77
+ it "assigns the requested experiment as @experiment" do
78
+ get :edit, {:id => experiment.to_param}, valid_session
79
+ assigns(:experiment).should eq(experiment)
59
80
  end
81
+ end
60
82
 
61
- it 'turns the requested experiment into CSV' do
62
- get :show, :id => @experiment.id, :format => 'csv'
63
- response.body.should eql( @experiment.to_csv )
83
+ describe "POST create" do
84
+ describe "with valid params" do
85
+ it "creates a new Experiment" do
86
+ expect {
87
+ post :create, {:experiment => valid_attributes}, valid_session
88
+ }.to change(Experiment, :count).by(1)
89
+ end
90
+
91
+ it "assigns a newly created experiment as @experiment" do
92
+ post :create, {:experiment => valid_attributes}, valid_session
93
+ assigns(:experiment).should be_a(Experiment)
94
+ assigns(:experiment).should be_persisted
95
+ end
96
+
97
+ it "redirects to the created experiment" do
98
+ post :create, {:experiment => valid_attributes}, valid_session
99
+ response.should redirect_to(Experiment.last)
100
+ end
64
101
  end
65
102
 
103
+ describe "with invalid params" do
104
+ it "assigns a newly created but unsaved experiment as @experiment" do
105
+ # Trigger the behavior that occurs when invalid params are submitted
106
+ Experiment.any_instance.stub(:save).and_return(false)
107
+ post :create, {:experiment => { }}, valid_session
108
+ assigns(:experiment).should be_a_new(Experiment)
109
+ end
110
+
111
+ it "re-renders the 'new' template" do
112
+ # Trigger the behavior that occurs when invalid params are submitted
113
+ Experiment.any_instance.stub(:save).and_return(false)
114
+ post :create, {:experiment => { }}, valid_session
115
+ response.should render_template("new")
116
+ end
117
+ end
66
118
  end
67
119
 
68
- context 'formatting HTML' do
120
+ describe "PUT update" do
121
+ describe "with valid params" do
122
+ it "updates the requested experiment" do
123
+ experiment = Experiment.create! valid_attributes
124
+ # Assuming there are no other experiments in the database, this
125
+ # specifies that the Experiment created on the previous line
126
+ # receives the :update_attributes message with whatever params are
127
+ # submitted in the request.
128
+ Experiment.any_instance.should_receive(:update).with({ "name" => "params" })
129
+ put :update, {:id => experiment.to_param, :experiment => { "name" => "params" }}, valid_session
130
+ end
131
+
132
+ it "assigns the requested experiment as @experiment" do
133
+ put :update, {:id => experiment.to_param, :experiment => valid_attributes}, valid_session
134
+ assigns(:experiment).should eq(experiment)
135
+ end
136
+
137
+ it "redirects to the experiment" do
138
+ put :update, {:id => experiment.to_param, :experiment => valid_attributes}, valid_session
139
+ response.should redirect_to(experiment)
140
+ end
141
+ end
142
+
143
+ describe "with invalid params" do
144
+ it "assigns the experiment as @experiment" do
145
+ experiment = Experiment.create! valid_attributes
146
+ # Trigger the behavior that occurs when invalid params are submitted
147
+ Experiment.any_instance.stub(:save).and_return(false)
148
+ put :update, {:id => experiment.to_param, :experiment => { }}, valid_session
149
+ assigns(:experiment).should eq(experiment)
150
+ end
151
+
152
+ it "re-renders the 'edit' template" do
153
+ experiment = Experiment.create! valid_attributes
154
+ # Trigger the behavior that occurs when invalid params are submitted
155
+ Experiment.any_instance.stub(:save).and_return(false)
156
+ put :update, {:id => experiment.to_param, :experiment => { }}, valid_session
157
+ response.should render_template("edit")
158
+ end
159
+ end
160
+ end
69
161
 
70
- it 'renders HTML' do
71
- get :show, :id => @experiment.id, :format => 'html'
72
- response.should be_success
73
- response.content_type.should eql( 'text/html' )
162
+ describe "DELETE destroy" do
163
+ it "destroys the requested experiment" do
164
+ expect {
165
+ delete :destroy, {:id => experiment.to_param}, valid_session
166
+ }.to change(Experiment, :count).by(-1)
74
167
  end
75
168
 
169
+ it "redirects to the experiments list" do
170
+ delete :destroy, {:id => experiment.to_param}, valid_session
171
+ response.should redirect_to(experiments_url)
172
+ end
76
173
  end
77
174
 
78
175
  end
79
-
80
- end
176
+ end
@@ -1 +1 @@
1
- <table><tr><th>id</th><td>1</td></tr><tr><th>name</th><td>test</td></tr><tr><th>description</th><td>this is only a test</td></tr><tr><th>created</th><td>2013-09-12 07:08:58 UTC</td></tr><tr><th>active</th><td>false</td></tr><tr><th>subjects</th><td>0</td></tr></table>
1
+ <table><tr><th>id</th><td>1</td></tr><tr><th>name</th><td>test</td></tr><tr><th>description</th><td>this is only a test</td></tr><tr><th>created</th><td>2013-09-12 07:08:58 UTC</td></tr><tr><th>subjects</th><td>0</td></tr></table>
@@ -1 +1 @@
1
- <table><tr><th>id</th><td>1</td></tr><tr><th>name</th><td>test</td></tr><tr><th>description</th><td>this is only a test</td></tr><tr><th>created</th><td>2013-09-12 07:08:58 UTC</td></tr><tr><th>active</th><td>false</td></tr><tr><th>subjects</th><td>0</td></tr></table>
1
+ <table><tr><th>id</th><td>1</td></tr><tr><th>name</th><td>test</td></tr><tr><th>description</th><td>this is only a test</td></tr><tr><th>created</th><td>2013-09-12 07:08:58 UTC</td></tr><tr><th>subjects</th><td>0</td></tr></table>
@@ -1 +1 @@
1
- <table border="1"><tr><th>id</th><th>name</th><th>active</th></tr><tr><td>1</td><td>test</td><td>false</td><td><a href="/experiments/show/1">Show</a></td></tr></table>
1
+ <table border="1"><tr><th>id</th><th>name</th></tr><tr><td>1</td><td>test</td><td><a href="/experiments/show/1">Show</a></td></tr></table>
@@ -1 +1 @@
1
- <table border="1"><tr><th>id</th><th>name</th><th>active</th></tr><tr><td>1</td><td>test</td><td>false</td><td><a href="/experiments/show/1">Show</a></td></tr></table>
1
+ <table border="1"><tr><th>id</th><th>name</th></tr><tr><td>1</td><td>test</td><td><a href="/experiments/show/1">Show</a></td></tr></table>
Binary file