Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pardot
Jul 25, 2001




You'd probably be a lot happier using d3 rather than anything else.

Adbot
ADBOT LOVES YOU

EAT THE EGGS RICOLA
May 29, 2008

Pardot posted:

You'd probably be a lot happier using d3 rather than anything else.

Yeah, I was mostly just curious if anything not-terrible existed.

hmm yes
Dec 2, 2000
College Slice

prom candy posted:

Is it common to write a test for all your relationships and validations? It seems like overkill to me.

I like to see them because they are low hanging fruit that ensure the foundation of your app is in place. It only takes a few minutes to add the tests with shoulda matchers. If it was a lot of effort to implement I would agree that it is overkill.

xtal
Jan 9, 2011

by Fluffdaddy
I actually test if my classes inherit from ActiveRecord::Base sometimes. You can't have too many tests.

prom candy
Dec 16, 2005

Only I may dance

xtal posted:

You can't have too many tests.

Is the amount of time that it takes to run your test suite not a concern?

xtal
Jan 9, 2011

by Fluffdaddy
Not as much of a concern as code correctness, that's for sure! Plus use Guard.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Like everything else in software engineering, every test has a cost, and you can very well go overboard with tests. With ruby and other dynamically typed languages, I find more useful to focus more on integration tests. In myexperience, they tend to catch bugs earlier than large number of extremely specific unit tests.

kayakyakr
Feb 16, 2004

Kayak is true

EAT THE EGGS RICOLA posted:

Are there any decent ruby gems for doing decent visualizations, in the form of graphs/charts/maps/anything? I have a bunch of varied datasets that I've been asked to make interesting with, and all of my code that works with the api is ruby-based so I'd like to just carry on with that.

There isn't really one. I was working on making one, but haven't fully gemified it yet. Ran out of time.

e: this is awful code and you should by no means copy it because it breaks about 20 standard rails conventions, but this makes a pretty nice line chart:
https://github.com/talho/epi_full/blob/master/app/views/svg/line.svg.erb

xtal
Jan 9, 2011

by Fluffdaddy
What's the ideal way to test Rails 4 concerns? Trying to switch my code base to use them more and they're being really irritating.

edit: http://www.dotnetguy.co.uk/post/2012/08/26/rails-rspec-testing-your-modules/

xtal fucked around with this message at 17:40 on Aug 25, 2013

Peristalsis
Apr 5, 2004
Move along.

What am I missing here? This looks like a God-awful way to construct anything. I've seen it recommended in a couple of places, but the API seems horrible, and constructing nested XML is nigh on impossible. Is there a better set of instructions than the minimal examples on the github and rubyforge sites? I guess I assumed that using this would be easier than building up XML as strings in my code, but I'm not seeing that at all.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
The good thing about libraries like Builder and Nokogiri::XML::Builder is that the structure of the code mirrors the structure of the resulting xml. For example,

Ruby code:
builder = Nokogiri::XML::Builder.new do |xml|
  xml.root {
    xml.products {
      xml.widget {
        xml.id_ "10"
        xml.name "Awesome widget"
      }
    }
  }
end

puts builder.to_xml
outputs

XML code:
<?xml version="1.0"?>
<root>
<products>
  <widget>
    <id>10</id>
    <name>Awesome widget</name>
  </widget>
</products>
</root>
The bad thing is that they're implemented via method_missing and metric poo poo-ton of closures, so performance is pretty terrible (even for ruby standards), and there's a risk of accidentally calling methods in Object (e.g. type or id).

Smol fucked around with this message at 17:18 on Aug 26, 2013

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
It makes me sad that XML is still so prevalent. Everything about it is so terrible.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
XML as a whole is too complex. But using a sane subset of it is just fine.

Also, at least they managed to standardize validation. Validating JSON in a standardized manner is horrible.

Smol fucked around with this message at 17:34 on Aug 26, 2013

Peristalsis
Apr 5, 2004
Move along.

Smol posted:

The good thing about libraries like Builder and Nokogiri::XML::Builder is that the structure of the code mirrors the structure of the resulting xml. For example,

Ruby code:
builder = Nokogiri::XML::Builder.new do |xml|
  xml.root {
    xml.products {
      xml.widget {
        xml.id_ "10"
        xml.name "Awesome widget"
      }
    }
  }
end

puts builder.to_xml
outputs

XML code:
<?xml version="1.0"?>
<root>
<products>
  <widget>
    <id>10</id>
    <name>Awesome widget</name>
  </widget>
</products>
</root>
The bad thing is that they're implemented via method_missing and metric poo poo-ton of closures, so performance is pretty terrible (even for ruby standards), and there's a risk of accidentally calling methods in Object (e.g. type or id).

Wait, do I have to use Nokogiri with Builder? I'm confused now - I thought they were alternate ways of doing the same things.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
They're different libraries. Nokogiri is a general purpose XML processing library which offers a Builder-like API for constructing XML documents as well. The big difference between Builder and Nokogiri::XML::Builder is that Nokogiri uses either libxml2 or a similar Java library under the hood, so it should be quite a bit faster.

Smol fucked around with this message at 17:42 on Aug 26, 2013

Peristalsis
Apr 5, 2004
Move along.

Smol posted:

They're different libraries. Nokogiri is a general purpose XML processing library which offers a Builder-like API for constructing XML documents as well. The big difference between Builder and Nokogiri::XML::Builder is that Nokogiri uses either libxml2 or a similar Java library under the hood, so it should be quite a bit faster.

Okay, sorry if I'm being dense, but let me back up. I'd like nice libraries to more easily parse and construct XML strings (and if the same gem could do both, that's even better). Someone suggested the Builder gem, but I found it difficult to understand, and nearly impossible to use. I'd like to get a better explanation of how it works, or (if it does just suck) other alternatives. Are you suggesting that Nokogiri is better?

Peristalsis fucked around with this message at 17:57 on Aug 26, 2013

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
If I had to choose between the two, I'd use Nokogiri for XML generation.

As for it being difficult to understand... I wouldn't call it that. I think they're both very easy to use. But maybe it's a bit more basic thing. Have you used Ruby (or some other language where anonymous functions are considered to be idiomatic) a lot in the past? Perhaps you're familiar with JavaScript?

Knowing your background might make it easier to explain how they work.

Smol fucked around with this message at 18:21 on Aug 26, 2013

Peristalsis
Apr 5, 2004
Move along.

Smol posted:

If I had to choose between the two, I'd use Nokogiri for XML generation.

As for it being impossible to understand... I wouldn't call it that. I think they're both very easy to use. But maybe it's a bit more basic thing. Have you used Ruby (or some other language where anonymous functions are considered idiomatic) a lot in the past?

I've been using Ruby for over 6 months, intermittently with Rails. I like Ruby well enough, but I've always found the documentation to be lacking, at least in organization.

For the current problem, I'll see if I can make Nokogiri do what I want, and forget about Builder for now. The main problems I was having with Builder were:
1) When trying things out in irb/Rails console, it appends an extraneous <inspect/> element - not the end of the world, but very distracting when I was trying to play with the tool to figure out what I was doing wrong.
2) I don't see a way to build up an XML string as I go along. I'm trying to model objects with a class hierarchy, and I had hoped to add elements and sub-elements to a single string/builder model as I looped over each collection. I really didn't want to have to make one huge instantiation call with every piece of information in it - keeping track of that would be far worse than building my own, simple xml generation routines in each class.
3) Getting nested elements and attributes to work without escape characters corrupting the end result was much, much harder than it needed to be.

Edit: For my background, I've been programming professionally since 1997, but mostly with more traditional tools. I've used VB and Java the most, with some work in Matlab, Perl, C/C++, AREV, and some Pascal and Mumps. There's probably one or two others that I'm not thinking of. I've hacked at some javascript to debug issues at a previous job, but never approached it systematically or anything.

Peristalsis fucked around with this message at 18:41 on Aug 26, 2013

kayakyakr
Feb 16, 2004

Kayak is true
For building XML responses, you could always use erb. create a view named action.xml.erb and write XML as if you were writing an HTML view.

This doesn't work as well if you're trying to send XML to a different webservice

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

kayakyakr posted:

This doesn't work as well if you're trying to send XML to a different webservice

Why not? I use erb to render to string all the time, including scenarios like that one.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat

xtal posted:

I actually test if my classes inherit from ActiveRecord::Base sometimes. You can't have too many tests.

This is dumb; you might as well be writing tests to make sure your models respond to Object methods.

xtal
Jan 9, 2011

by Fluffdaddy

Novo posted:

This is dumb; you might as well be writing tests to make sure your models respond to Object methods.

TDD is writing tests first and having them tell you what code to write. Testing your class's inheritance is a perfectly logical starting point and there's literally no downside aside from an extra few milliseconds when you first start your tests.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Of course there is a downside. It's another test you have to maintain.

Smol fucked around with this message at 19:54 on Aug 26, 2013

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013

Smol posted:

Like everything else in software engineering, every test has a cost, and you can very well go overboard with tests. With ruby and other dynamically typed languages, I find more useful to focus more on integration tests. In myexperience, they tend to catch bugs earlier than large number of extremely specific unit tests.

I like specific unit tests when I need to know that a method I'm changing still returns the same values for the same inputs. I mean, integration tests are great for finding real bugs, but unit tests are basically what tell me that a method's behavior includes the particular things I need it to.

It's really nice when I change something and my left-over unit tests let me know I screwed up, but it seems like the biggest thing they do (for my small, ~4-5k LOC projects) is tell me when I've implemented some component in a way that satisfies my specifications for it.

My most recent project was all hosed up when I finally built all the components and ran it as an application, even though each component passed its unit tests and satisfied the specific requirements I laid out.

Safe and Secure! fucked around with this message at 20:02 on Aug 26, 2013

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

xtal posted:

TDD is writing tests first and having them tell you what code to write. Testing your class's inheritance is a perfectly logical starting point and there's literally no downside aside from an extra few milliseconds when you first start your tests.

TDD is driving your development with tests, not writing your code once in test form and once in implementation form.

Testing inheritance actively hurts you, because you'll have to fix that test if you change the class's implementation (say, from ActiveRecord to DataMapper or Ripple or a plain old Object that calls methods on other classes).

I justify testing associations by using it as a design phase: I mash out association tests, pending tests for features that haven't been implemented, and validations I'll know I want. Then I use the test output as a gauge to know when I'm done.

coronalight
Oct 12, 2006

asdfghjkl;
Are there any robust CMS/blogging services currently available that are similar in functionality to Wordpress? I'm really sick of Wordpress becoming more and more clogged up with each release and would love a more open and fluid coding process when I'm building features. Googling turns up some results, but nothing that seems to have a solid userbase/community. Am I stuck with PHP?

Oh My Science
Dec 29, 2008
I have been toying around with locomotiveCMS and it seems OK. Would love some input on it if anyone has used it in production.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat

Cocoa Crispies posted:

TDD is driving your development with tests, not writing your code once in test form and once in implementation form.

Testing inheritance actively hurts you, because you'll have to fix that test if you change the class's implementation (say, from ActiveRecord to DataMapper or Ripple or a plain old Object that calls methods on other classes).

I justify testing associations by using it as a design phase: I mash out association tests, pending tests for features that haven't been implemented, and validations I'll know I want. Then I use the test output as a gauge to know when I'm done.

Exactly. If you are defining classes at runtime then testing a parent class is defensible, but testing that "class Foo < Bar" has the desired effect is way outside the scope of what you should be testing, TDD or no.

prom candy
Dec 16, 2005

Only I may dance

scotty posted:

Are there any robust CMS/blogging services currently available that are similar in functionality to Wordpress? I'm really sick of Wordpress becoming more and more clogged up with each release and would love a more open and fluid coding process when I'm building features. Googling turns up some results, but nothing that seems to have a solid userbase/community. Am I stuck with PHP?

My company has a semi-open source CMS that we use for our client sites. We'd like to build widespread adoption but at this point the docs aren't there and the code needs some (a lot of) cleanup. It's still functionally complete and pretty nice to work with. PM me if you're interested and I'll set you up, I'd definitely love to get feedback from someone outside our team.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

What could cause a 422 error on an AWS deploy but work perfectly fine on my local machine? Submitting an POST through AJAX to update a record. It works fine on my local machine but returns a 422 on the staging server.

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
Is there any easy way to do a one time dump from an access DB into my postgres DB?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

scotty posted:

Are there any robust CMS/blogging services currently available that are similar in functionality to Wordpress? I'm really sick of Wordpress becoming more and more clogged up with each release and would love a more open and fluid coding process when I'm building features. Googling turns up some results, but nothing that seems to have a solid userbase/community. Am I stuck with PHP?

The only CMSes worth using are Wordpress you don't host and one you've written to match your own particular needs. Every CMS is terrible, but Wordpress is well-supported.

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

Cocoa Crispies posted:

The only CMSes worth using are Wordpress you don't host and one you've written to match your own particular needs. Every CMS is terrible, but Wordpress is well-supported.

It's not quite a CMS, but I've really enjoyed using Octopress lately.

Pardot
Jul 25, 2001




raej posted:

Is there any easy way to do a one time dump from an access DB into my postgres DB?

It looks like Sequel can maybe connect to Access, but I have no idea. Can you dump your access tables to CSV? If so you could use copy

Fillerbunny
Jul 25, 2002

so confused.

Novo posted:

Exactly. If you are defining classes at runtime then testing a parent class is defensible, but testing that "class Foo < Bar" has the desired effect is way outside the scope of what you should be testing, TDD or no.

How do you determine what's in scope?

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat

Fillerbunny posted:

How do you determine what's in scope?

I test the methods I've implemented, not the ones Ruby implements. I also don't test things that are implemented by frameworks or libraries I'm using.

I set up the preconditions (if necessary), feed my code inputs, and check that the outputs conform to my expectations. I don't test that the implementation was expressed in a particular way, because that's not what tests are for.

OOP is supposed to help you separate the "what" from the "how", the interface from the implementation, etc. When I am refactoring part of my implementation, I want my failed tests to tell me "hey, these things stopped working the way they're supposed to!" not "hey, you forgot to subclass FooBarBaz!"

Basically, even a clean well-designed OO codebase is full of assumptions, conventions, and other implicit behaviors. Testing should be about making these things explicit so that if you decide to change a class hierarchy or whatever, you have a way of knowing that you still conform. If your test just fails because you did some refactoring (but didn't change the behavior in any way) then it's not useful.

Novo fucked around with this message at 00:10 on Aug 30, 2013

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013

Fillerbunny posted:

How do you determine what's in scope?

Isn't this why "behavior driven development" took off? Because test-driven development was a thing, and everyone started letting their tests drive their development, and then people started wondering how much to test, and then some people went "just test behavior!"?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Fillerbunny posted:

How do you determine what's in scope?
Experience, responsibility, and laziness. "Don't test things you didn't write," seems like a reasonable starting point.

Safe and Secure! posted:

Isn't this why "behavior driven development" took off? Because test-driven development was a thing, and everyone started letting their tests drive their development, and then people started wondering how much to test, and then some people went "just test behavior!"?
TDD and BDD are the same, except saying "BDD" probably means you're using rspec and being very self-congratulatory about it.

Good TDD isn't testing what your poo poo inherits from, it's testing what your poo poo does.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

Can you dump your access tables to CSV? If so you could use copy

Access can absolutely dump to CSV.

Adbot
ADBOT LOVES YOU

hmm yes
Dec 2, 2000
College Slice

Cocoa Crispies posted:

TDD and BDD are the same, except saying "BDD" probably means you're using rspec and being very self-congratulatory about it.

Hahaha, this is so true and I love it. I use rspec

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply