Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate question posting form temp fixes #910 #944

Closed

Conversation

sandyvern
Copy link
Collaborator

@sandyvern sandyvern commented Nov 1, 2016

Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!

  • all tests pass -- rake test:all
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request is descriptively named with #number reference back to original issue
  • if possible, multiple commits squashed if they're smaller changes
  • reviewed/confirmed/tested by another contributor or maintainer
  • schema.rb.example has been updated if any database migrations were added

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software

We have a loose schedule of reviewing and pulling in changes every Tuesday and Friday, and publishing changes on Fridays. Please alert developers on plots-dev@googlegroups.com when your request is ready or if you need assistance.

Thanks!

@jywarren
Copy link
Member

jywarren commented Nov 2, 2016

Checking out your cloud9 setup -- wasn't clear if ./install_cloud9.sh was run already, but I'm running that now as per https://github.com/publiclab/plots2/#simple-installation-with-cloud9

it seems to run rake db:setup which is supposed to sort of skip rake db:migrate -- and tests seem to pass now! How's that look to you?

@jywarren
Copy link
Member

jywarren commented Nov 2, 2016

sandyvern:~/workspace (master) $ rake test:units                                                                   
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:Image> at /home/ubuntu/workspace/app/models/image.rb:12)
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:User> at /home/ubuntu/workspace/app/models/user.rb:21)
Loaded suite /usr/local/rvm/gems/ruby-2.1.2/gems/rake-10.5.0/lib/rake/rake_test_loader
Started
..............................................................................................................................
.

Finished in 3.284613645 seconds.
------------------------------------------------------------------------------------------------------------------------------
127 tests, 396 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
------------------------------------------------------------------------------------------------------------------------------
38.67 tests/s, 120.56 assertions/s

@jywarren
Copy link
Member

jywarren commented Nov 2, 2016

This looks good - and at some point, we should add a test for the /questions/new action itself; I believe right now, there needn't be an actual defined controller action, due to Rails defaults (it just makes up an empty one if it finds the appropriate template) but we can still add a test like this to the questions controller test:

test "/questions/new form loads" do
  get :new

  assert_response :success
end

I think?

@sandyvern
Copy link
Collaborator Author

sandyvern commented Nov 2, 2016

Thanks for checking things out! I thought I had run ./install_cloud9.sh sorry if that was the reason I was running into difficulties!

For the /questions/new test should that be just be added at the end of the other tests or is there a better place to insert that?

Will I run into issues since you did the changes on my master branch? I don't want to have merge conflicts if I change something on my branch...lol...causes me stress :-)

@jywarren
Copy link
Member

jywarren commented Nov 2, 2016

Yes, at the end sounds great. At some point we could try to re-order the
methods and the matching tests to some semblance of order!

On Wed, Nov 2, 2016 at 3:54 PM, Sandy notifications@github.com wrote:

Thanks for checking things out! I thought I had run ./install_cloud9.sh
sorry if that was the reason I was running into difficulties!

For the /questions/new test should that be just be added at the end of the
other tests or is there a better place to insert that?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#944 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AABfJ2KMsa8Mlo7SngSoghVI819YgvH4ks5q6OpfgaJpZM4KmiBR
.

@sandyvern
Copy link
Collaborator Author

sandyvern commented Nov 2, 2016

I have added the /question/new test...but looks like this is still failing in TravisCI:

Failure:
  Expected at least 1 element matching "input#title", found 0.
  <false> is not true.
test_search_a_question_and_go_through_post_mechanism_if_question_not_found_when_user_is_not_logged_in(LoginFlowTest)
test/integration/login_flow_test.rb:33:in `block in <class:LoginFlowTest>'

@jywarren
Copy link
Member

jywarren commented Nov 2, 2016

You know, I believe that test on line 33 of test/integration/login_flow_test.rb is to ensure that you can't begin authoring a question when you're not logged in -- so the changes you made to the test at test/functional/editor_controller_test.rb would have to be copied in there too -- it'll also go to your new form. Make sense? Thanks!

@@ -45,8 +45,10 @@ def setup
tags: 'question:question,one',
template: 'question',
redirect: 'question'
assert_select "h3", "Ask a question of the community"
assert_select "input#taginput[value=?]", "question:question,one"
assert_response :redirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to worry about details, but if you could adjust this indent (two spaces per indent) that'd be great. It's helpful when the whole codebase has really standardized formatting. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, just to be clear, if it matches level of indent of the line below it that'd be perfect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about details too :-) So all the assert lines should line up? And do you want me to actually delete the 2 lines I commented out:

assert_select "h3", "Ask a question of the community"
assert_select "input#taginput[value=?]", "question:question,one"

I commented them out just cause the original issue didn't seem clear about whether or not they should be out or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unless you want to try modifying them to fit your new template -- and in fact, both may still work, since your template is almost identical to the previous one. Each looks for an HTML element (h3 or input) and the second also looks to see that the <input> it finds has the specified value. They will actually reference these two lines in your new template:

So, try uncommenting them to see if they pass!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly they don't seem to pass when I uncomment them either. And as far as I can tell the h3 is there...the <input> I am not entirely sure on but seems to be referencing tags with questions so sort of at a loss.

@jywarren
Copy link
Member

jywarren commented Nov 3, 2016

Regarding the login_flow_test, I'm not actually sure of that one, and it could be a bit of a puzzler. I'm wondering if the redirect happens at all? We do follow_redirect!, but we don't actually assert that a redirect happened. Anyhow, as I said, if just before the follow_redirect!, we add:

assert_response :redirect
assert_redirected_to  '/questions/new'

...just as you did in the other test, at least we'll know that redirecting is working...

@jywarren
Copy link
Member

jywarren commented Nov 3, 2016

Ah, I remembered that you can't select things after a redirect in a
functional test. You can in an integration test, like the other one I was
mentioning -- after the follow_redirect! command. So I guess remove them
from this test, but try to leave them in the integration test!

On Nov 3, 2016 7:02 PM, "Sandy" notifications@github.com wrote:

@sandyvern commented on this pull request.

In test/functional/editor_controller_test.rb
#944:

@@ -45,8 +45,10 @@ def setup
tags: 'question:question,one',
template: 'question',
redirect: 'question'

  • assert_select "h3", "Ask a question of the community"
  • assert_select "input#taginput[value=?]", "question:question,one"
  •    assert_response :redirect
    

Sadly they don't seem to pass when I uncomment them either. And as far as
I can tell the h3 is there...the I am not entirely sure on but
seems to be referencing tags with questions so sort of at a loss.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#944, or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ4mwVqSuhcacC1hRQjfREd70a3A0ks5q6mgCgaJpZM4KmiBR
.

@sandyvern
Copy link
Collaborator Author

sandyvern commented Nov 4, 2016

I have commented out the assert_select lines from editor_controller_test.rb but it didn't seem to make a difference. At the moment I have inserted the:

assert_response :redirect
assert_redirected_to  '/questions/new'

into the login_flow_test file. Which didn't seem to help the problem either. I was getting a failure about the input#title so I ended up commenting out these two lines:

# assert_select "input#title" do
# assert_select "[value=?]", "What"

which managed to get the tests I ran locally not to have any failures but still had errors:

rake test:all
Running Rails tests
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:Image> at /home/ubuntu/workspace/app/models/image.rb:12)
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:User> at /home/ubuntu/workspace/app/models/user.rb:21)
Loaded suite /usr/local/rvm/gems/ruby-2.1.2/gems/rake-10.5.0/lib/rake/rake_test_loader
Started
.................................................................................................................................

Finished in 3.010216647 seconds.
------------------------------------------------------------------------------------------------------------------------------------------------------------
129 tests, 400 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
------------------------------------------------------------------------------------------------------------------------------------------------------------
42.85 tests/s, 132.88 assertions/s
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:Image> at /home/ubuntu/workspace/app/models/image.rb:12)
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:User> at /home/ubuntu/workspace/app/models/user.rb:21)
Loaded suite /usr/local/rvm/gems/ruby-2.1.2/gems/rake-10.5.0/lib/rake/rake_test_loader
Started
..............................................................E
============================================================================================================================================================
Error: test_newcomer_should_get_post_form(EditorControllerTest): NoMethodError: undefined method `include?' for nil:NilClass
app/controllers/editor_controller.rb:15:in `post'
test/functional/editor_controller_test.rb:26:in `block in <class:EditorControllerTest>'
============================================================================================================================================================
....E
============================================================================================================================================================
Error: test_should_show_title_form_input_if_title_parameter_present(EditorControllerTest): NoMethodError: undefined method `include?' for nil:NilClass
app/controllers/editor_controller.rb:15:in `post'
test/functional/editor_controller_test.rb:56:in `block in <class:EditorControllerTest>'
============================================================================================================================================================
.......................................................E
============================================================================================================================================================
Error: test_/questions/new_form_loads(QuestionsControllerTest): AbstractController::ActionNotFound: The action 'new' could not be found for QuestionsController
test/functional/questions_controller_test.rb:164:in `block in <class:QuestionsControllerTest>'
============================================================================================================================================================
.......................................................................................................................

Finished in 30.561284915 seconds.
------------------------------------------------------------------------------------------------------------------------------------------------------------
243 tests, 576 assertions, 0 failures, 3 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
------------------------------------------------------------------------------------------------------------------------------------------------------------
7.95 tests/s, 18.85 assertions/s
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:Image> at /home/ubuntu/workspace/app/models/image.rb:12)
DEPRECATION WARNING: [paperclip] [deprecation] Rails 3.2 and 4.1 are unsupported as of Rails 5 release. Please upgrade to Rails 4.2 before upgrading paperclip. (called from <class:User> at /home/ubuntu/workspace/app/models/user.rb:21)
Loaded suite /usr/local/rvm/gems/ruby-2.1.2/gems/rake-10.5.0/lib/rake/rake_test_loader
Started
................................................E
============================================================================================================================================================
Error: test_users_are_logged_out_and_alerted_when_banned,_and_notes_are_not_accessible(ModerateAndBanTest): NoMethodError: undefined method `include?' for nil:NilClass
app/controllers/editor_controller.rb:15:in `post'
test/integration/moderate_and_ban_test.rb:12:in `block in <class:ModerateAndBanTest>'
============================================================================================================================================================
E
============================================================================================================================================================
Error: test_users_are_logged_out_and_alerted_when_moderated,_and_notes_are_not_accessible(ModerateAndBanTest): NoMethodError: undefined method `include?' for nil:NilClass
app/controllers/editor_controller.rb:15:in `post'
test/integration/moderate_and_ban_test.rb:60:in `block in <class:ModerateAndBanTest>'
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /home/ubuntu/workspace/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

So not sure if that means we are making progress or not :-)
I'm also not sure that the TravisCI test are running for me.

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

Ah - well, that's caused by this line:

https://github.com/sandyvern/plots2/blob/4921332a9371626a50f2bb26b77f487ef940d762/app/controllers/editor_controller.rb#L15

And could probably be solved by checking if params[:tags] is nil, first:

    redirect_to '/questions/new' if params[:tags] && params[:tags].include?("question:")

Make sense? Also -- even if it causes an error, pushing up another commit lets me be sure that the code I'm looking at in your PR is the same as what's causing the errors, so that can be helpful. But it was unnecessary in this case, just mentioning!

Thanks for your patience on this one, sometimes a small change ricochets through the tests -- but it's good that we catch these issues!

@sandyvern
Copy link
Collaborator Author

Might be getting somewhere :-) Down to one error...

Error: test_/questions/new_form_loads(QuestionsControllerTest): AbstractController::ActionNotFound: The action 'new' could not be found for QuestionsController
test/functional/questions_controller_test.rb:164:in `block in <class:QuestionsControllerTest>' 

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

Hmm, i'm not actually sure -- i thought just having a template would create an implicit method for new but i guess not?

Can you try just adding a blank method for it?

def new
end

into the questions controller?

@sandyvern
Copy link
Collaborator Author

Adding the blank 'new' method still doesn't quite work...gives me this:

Error: test_/questions/new_form_loads(QuestionsControllerTest):
  ActionView::MissingTemplate: Missing template questions/new, application/new with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :jbuilder]}. Searched in:
    * "/home/ubuntu/workspace/app/views"
    * "/usr/local/rvm/gems/ruby-2.1.2/gems/grape-swagger-ui-0.1.0/app/views"
    * "/usr/local/rvm/gems/ruby-2.1.2/gems/grape-swagger-rails-0.3.0/app/views"
    * "/usr/local/rvm/gems/ruby-2.1.2/gems/jasmine-rails-0.14.1/app/views"
test/functional/questions_controller_test.rb:164:in `block in <class:QuestionsControllerTest>'

Question (beware possibly total newb question :-) )...the original issue said to:

If you'd like to do this before #904, you can just copy the template at /app/views/editor/post.html.erb to /app/views/editor/question.html.erb and the redirects will be in place -- the actual template redesign in #904 can then follow.

Is that error looking for a template in 'questions/new' views?

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

Aha, great catch! You're right -- we need to tell the method where to find the template, since it's under the /app/views/editor/ folder instead of /app/views/questions/ -- so you can add one line to the method:

def new
  render "questions/new"
end

I think that's right -- fingers X!!

@sandyvern
Copy link
Collaborator Author

sandyvern commented Nov 4, 2016

I had high hopes but 👎

Error: test_/questions/new_form_loads(QuestionsControllerTest):
  ActionView::MissingTemplate: Missing template questions/new with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :jbuilder]}. Searched in:
    * "/home/ubuntu/workspace/app/views"
    * "/usr/local/rvm/gems/ruby-2.1.2/gems/grape-swagger-ui-0.1.0/app/views"
    * "/usr/local/rvm/gems/ruby-2.1.2/gems/grape-swagger-rails-0.3.0/app/views"
    * "/usr/local/rvm/gems/ruby-2.1.2/gems/jasmine-rails-0.14.1/app/views"
app/controllers/questions_controller.rb:13:in `new'
test/functional/questions_controller_test.rb:164:in `block in <class:QuestionsControllerTest>'

I guess I am a little confused...wouldn't we want to do:

def new
  render "editor/question"
end

Where as this:

def new
  render "questions/new"
end

suggests to me that there would be a file called new.html.erb in the directory questions?

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

You're right again... I think i've been looking at too many Github issues
today. "editor/question" is the correct thing to use! Apologies!!

On Fri, Nov 4, 2016 at 2:41 PM, Sandy notifications@github.com wrote:

I had high hopes but 👎

I guess I am a little confused...wouldn't we want to do:

def new
render "editor/question"
end

Where as this:

def new
render "questions/new"
end

suggests to me that there would be a file called new.html.erb in the
directory questions?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#944 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AABfJ0lTrilwJemFp7kNheru97gg3vPoks5q63xYgaJpZM4KmiBR
.

@sandyvern
Copy link
Collaborator Author

sandyvern commented Nov 4, 2016

Does that mean I would need to change all the instances of 'questions/new' that I have inserted into the various other places? Or does that mean it might be easier to create the template in questions/new.html.erb?

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

No, I believe the route will remain the same -- this render command is just the pointer to the template file. Because of the routes.rb entry, all external requests (including redirect_tos) will follow that to the Questions controller.

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

Rails defaults like this can trip you up... although Rails is very powerful, when you break a convention (like putting the template in a different place) it can get a little complex. I guess I felt we should keep all the posting forms next to one another, though!

@sandyvern
Copy link
Collaborator Author

Didn't quite fix it...but we have a new error:

Error: test_/questions/new_form_loads(QuestionsControllerTest): ActionView::Template::Error: undefined method uid' for nil:NilClass app/views/editor/question.html.erb:5:in``` _app_views_editor_question_html_erb___111950541617756209_112549200'
app/controllers/questions_controller.rb:13:in new' test/functional/questions_controller_test.rb:164:inblock in class:QuestionsControllerTest'

@jywarren jywarren changed the title Seperate ques posting form temp #910 Separate question posting form temp fixes #910 Nov 4, 2016
@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

Ah, i think perhaps we have to log in to view the form, so adding this as the first line of the test on line 164 would do that:

    UserSession.create(rusers(:bob))

Make sense? I hope this is the last thing!

@jywarren
Copy link
Member

jywarren commented Nov 4, 2016

@sandyvern
Copy link
Collaborator Author

I have added the UserSession line to the test and it seems to have worked locally...until it got to the Solr tests which had 2 failures.
On a side note...I have been committing my code, rebasing, merging etc all day but does seem to be triggering the TravisCI test to run. So not sure how to get it back functioning correctly...you are still on as a collaborator on my c9 if you need to check it out.

@jywarren
Copy link
Member

jywarren commented Nov 5, 2016

OK - well, for the TravisCI tests, maybe you're not doing git push -f origin feature-branch-name each time? That should force push up your
latest changes and trigger TravisCI, and can be easy to forget.

As for the Solr tests, you shouldn't need to run them yourself; regular
rake test should skip them, and you can let them run on the TravisCI
build. The idea is that they're hard to break, since their functionality is
kept quite separate from the rest of the system, so they don't need to be
run each time... or at least that's the idea.

Thanks, Sandy!!!

On Nov 4, 2016 8:44 PM, "Sandy" notifications@github.com wrote:

I have added the UserSession line to the test and it seems to have worked
locally...until it got to the Solr tests which had 2 failures.
On a side note...I have been committing my code, rebasing, merging etc all
day but does seem to be triggering the TravisCI test to run. So not sure
how to get it back functioning correctly...you are still on as a
collaborator on my c9 if you need to check it out.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#944 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AABfJ1CzTA58NhWQhIjhNZEa6mreVUHAks5q69FjgaJpZM4KmiBR
.

@sandyvern sandyvern force-pushed the seperate-ques-posting-form-temp branch from 4921332 to bd128e4 Compare November 5, 2016 17:19
@sandyvern
Copy link
Collaborator Author

I guess I didn't know about git push -f origin feature-branch-name... I was doing the git merge add-map-tags --ff-only which is in the directions of the sample git work flow. And the Solr tests just started automatically when I did therake test:all as the first step of the checkboxes.

@sandyvern
Copy link
Collaborator Author

sandyvern commented Nov 5, 2016

Yay!! They passed finally!! :-) Thanks for being patient with me and my newb issues!

@jywarren
Copy link
Member

jywarren commented Nov 6, 2016

Oh, i'm sorry if it wasn't clearly documented -- any suggestions of a way to make that more clear to folks? It's easy to overlook things when you're writing documentation so we appreciate the tips.

And SUPER!!! I'll look this over one more time and merge pretty soon. Thanks a million for your patience and persistence on this one -- we really appreciate it! I hope it wasn't too frustrating and that you'll consider taking on a new project with us soon!

@sandyvern
Copy link
Collaborator Author

Wasn't too frustrating at all...kind of enjoyed it :-) And will definitely look for other projects to contribute to.

As far as git push -f origin feature-branch-name, I would suggest adding it to the sample workflow...not exactly where it should go. Not sure if it should go at the end of #4 or after merging your feature branch in #6. I know for myself, I reference that workflow each time because want to make sure I am doing things correctly.

The other thing you might consider adding to that workflow is what to do when you rebase the master branch when there is a difference...never exactly sure what I should be doing...like adding another commit message, exiting that screen, then choosing y/n...so it might be a little confusing to first-timers/newbies.

@ryzokuken
Copy link
Member

ryzokuken commented Nov 6, 2016

@sandyvern We're planning to do major changes in the README, simplifying instructions and making every instruction simple and foolproof. We'll make sure to include everything.

Considering the rebase, I've always used the following:

# Fetch latest code from upstream
git fetch upstream
# Switch to master
git checkout master branch
# Merge upstream/master into master
git merge upstream/master
# Switch to my-branch branch
git checkout my-branch
# Rebase your commits on top of master
git rebase master
# Push to origin/master and origin/my-branch
git push -f origin master
git push -f origin my-branch

@jywarren
Copy link
Member

jywarren commented Nov 7, 2016

Excellent -- squashed and merged manually in a564ffd -- i added one more change to preserve the URL parameters. This is super, thanks so much!

@jywarren jywarren closed this Nov 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants